@Listeners({ TestNGLisetenerScreen.class })
public class LoginCase {
private static Logger logger = Logger.getLogger(LoginCase.class);
public WebDriver driver;
public LoginHandle loginHandle;
//@Optional("https://www.imooc.com")
@Parameters({"url"})
@BeforeClass
public void beforeClass(@Optional("https://www.baidu.com")String url) {
System.out.println(url);
// 引入log4j的配置文件(重点)
PropertyConfigurator.configure("log4j.properties");
logger.debug("初始化浏览器");
driver = new ChromeDriver();
logger.debug("打开浏览器");
driver.get(url);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
loginHandle = new LoginHandle(driver);
loginHandle.clikBtn();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@AfterClass
public void afterClass() {
driver.close();
}
/**
* case 2 1.判断登录是否成功 2.登录错误截图
*
* @Optional({"17828895362,s45s464"}String username,String password)
*/
@Parameters({"username","password"})
@Test
public void isLoginCase(String username,String password) {
loginHandle.sendEmail(username);
loginHandle.sendPassword(password);
loginHandle.clickLoginBtn();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 拿到用户的登录名
String usertext = loginHandle.GetUserText();
// 用断言判断登录的信息与用户名信息是否相同
Assert.assertEquals(usertext, "慕勒80185");
logger.error("登录失败+isLoginCase");
}
/**
* case 1 用户登录
* @return
*/
@Parameters({"username","password"})
@Test
public void loginCase(String username,String password) {
logger.debug("执行第一个case");
loginHandle.sendEmail(username);
loginHandle.sendPassword(password);
loginHandle.clickLoginBtn();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 拿到用户的登录名s
String usertext = loginHandle.GetUserText();
// 用断言判断登录的信息与用户名信息是否相同
Assert.assertEquals(usertext, "慕勒801805");
}
}
@Optional(“https://www.baidu.com”)url加了这个是可以跳转到百度的,但是不加就报错