我的包中有3个测试类。 首先配置:
public class PageVisibilityConfig {
WebDriver driver;
@BeforeSuite
public void beforeSuite() {
DOMConfigurator.configure("log4j.xml");
Log.startTestCase("Page Visibility Suite");
Log.info(Thread.currentThread().getStackTrace()[1].getMethodName());
driver = BrowserFactory.getBrowser("Firefox");
}
@AfterSuite(enabled = true)
public void afterSuite() {
Log.info(Thread.currentThread().getStackTrace()[1].getMethodName());
BrowserFactory.closeAllDriver();
Log.endTestCase("Page Visibility Suite");
}
@AfterGroups(groups = { "admin", "user" })
public void afterGroupLogOut() {
Log.info(Thread.currentThread().getStackTrace()[1].getMethodName());
UserMenu usermenu = PageFactory.initElements(driver, UserMenu.class);
usermenu.activeteUserMenu();
usermenu.logout();
}
}
第一个真正的测试类:
public class PageVisibilityAdmin {
WebDriver driver;
@BeforeClass(groups = { "admin" }, enabled = true)
public void beforeClassLogin() {
driver = BrowserFactory.getBrowser("Firefox");
Log.startTestCase("Page Visibility Admin test cases");
Log.info(Thread.currentThread().getStackTrace()[1].getMethodName());
LogIn login = PageFactory.initElements(driver, LogIn.class);
login.signupLogin();
login.loginViaCredentials();
UserMenu usermenu = PageFactory.initElements(driver, UserMenu.class);
usermenu.activeteUserMenu();
Assert.assertTrue(usermenu.isAdmin());
}
@DataProvider(name = "visibility_admin")
public static String[][] providedData() {
return com.resources.SQLConForDataProvider
.executeQuery("SELECT url FROM cdb_1cc755a513.visibility where admin='1' limit 1");
}
@Test(dataProvider = "visibility_admin", groups = { "admin" }, enabled = true)
public void adminRun(String url) {
Log.info(Thread.currentThread().getStackTrace()[1].getMethodName());
Log.info("Try " + Util.SUT + url);
driver.get(Util.SUT + url);
Log.info("Actual page " + driver.getCurrentUrl());
Assert.assertEquals(driver.getCurrentUrl(), Util.SUT + url);
Assert.assertFalse(driver.getTitle().toLowerCase().contains("not found"));
Assert.assertFalse(driver.getTitle().toLowerCase().contains("login"));
Assert.assertFalse(driver.getTitle().toLowerCase().contains("error"));
}
}
问题第三:
public class PageVisibilityUser {
WebDriver driver;
@BeforeClass(groups = { "user" }, enabled = true)
public void beforeGroupsLogin() {
driver = BrowserFactory.getBrowser("Firefox");
Log.startTestCase("Page Visibility User test cases");
Log.info(Thread.currentThread().getStackTrace()[1].getMethodName());
LogIn login = PageFactory.initElements(driver, LogIn.class);
login.signupLogin();
login.loginViaFacebook();
UserMenu usermenu = PageFactory.initElements(driver, UserMenu.class);
usermenu.activeteUserMenu();
Assert.assertFalse(usermenu.isAdmin());
}
@DataProvider(name = "visibility_user")
public static String[][] providedData() {
return com.resources.SQLConForDataProvider
.executeQuery("SELECT url FROM cdb_1cc755a513.visibility where not_added_user='1' limit 1");
}
@Test(dataProvider = "visibility_user", groups = { "user" }, enabled = true)
public void userRun(String url) {
Log.info(Thread.currentThread().getStackTrace()[1].getMethodName());
Log.info("Try " + Util.SUT + url);
driver.get(Util.SUT + url);
Log.info("Actual page " + driver.getCurrentUrl());
Assert.assertEquals(driver.getCurrentUrl(), Util.SUT + url);
Assert.assertFalse(driver.getTitle().toLowerCase().contains("not found"));
Assert.assertFalse(driver.getTitle().toLowerCase().contains("login"));
Assert.assertFalse(driver.getTitle().toLowerCase().contains("error"));
}
}
基本上我正在检查url是否可用于不同的角色。 我的问题是: 如果我将这些类作为套件或包运行,则最后一个类在sql结果集中失败并带有“额外行”(为空)。 如果我只运行配置类和它运行的最后一个类没有错误。 而异常(这很奇怪):
运行TestSuite java.sql.SQLException:结果集结束后 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)at at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)at at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)at at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)at at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:787)at at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5244) 在com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5167) 在 com.resources.SQLConForDataProvider.executeQuery(SQLConForDataProvider.java:47) 在 com.pageVisibility.PageVisibilityUser.providedData(PageVisibilityUser.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)