提示(Parameter ‘url’ is required by BeforeClass on method beforeClass but has not been marked @Optional or defined) 有拿老师的代码运行也这样,直接执行testng.xml或者使用@Optional都能正确执行,是否是testng版本的问题?用的7.0
package com.gcf.runcase;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.gcf.Immoc.TestNGListenerScreen;
import com.gcf.handle.LoginHandle;
@Listeners({TestNGListenerScreen.class})
public class LoginCase{
public static Logger logger = Logger.getLogger(LoginCase.class);
public WebDriver driver;
LoginHandle loginhandle;
@Parameters({"url"})
@BeforeClass
public void beforeClass(String url) {
PropertyConfigurator.configure("log4j.properties");
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
System.out.println("this is beforeClass");
driver = new ChromeDriver();
driver.get(url);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
loginhandle = new LoginHandle(driver);
loginhandle.ClickSigninButton();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@AfterClass
public void afterClass() {
System.out.println("this is afterClass");
driver.close();
}
/*@Test
public void TestLoginerror() {
System.out.println("this is case to test fail");
loginhandle.SendEmail("guocaif@cn.ibm.com");
loginhandle.SendPassword("xiaofeng1231111");
//loginhandle.ClickSevenBox();
loginhandle.ClickLoginButton();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String username = loginhandle.GetUserText();
Assert.assertEquals(username, "慕少5264998");
}*/
//默认没有在XML中取到值, 使用@Optional("guocaif@cn.ibm.com,111111")
@Parameters({"username","password"})
@Test
public void TestLoginSuccess(String username,String password) {
System.out.println("this is case to test TestLoginSuccess");
loginhandle.SendEmail(username);
loginhandle.SendPassword(password);
//loginhandle.ClickSevenBox();
loginhandle.ClickLoginButton();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String username1 = loginhandle.GetUserText();
Assert.assertEquals(username1, "慕少5264998");
}
@BeforeTest
public void beforeTest() {
System.out.println("this is beforeTest");
}
@AfterTest
public void afterTest() {
System.out.println("this is afterTest");
}
}