Java 同一类中的依赖方法只有在包含在“;“testng套件”;;独立地运行类尊重依赖关系
我有一个使用TestNG注释的依赖方法的类Java 同一类中的依赖方法只有在包含在“;“testng套件”;;独立地运行类尊重依赖关系,java,webdriver,selenium-webdriver,testng,Java,Webdriver,Selenium Webdriver,Testng,我有一个使用TestNG注释的依赖方法的类 dependsOnMethods 如果我只是从包中将其作为TestNG测试运行,那么测试在100%的时间内运行良好 当我将测试包含在TestNG套件中时,这些方法会无序运行。是的,我正在使用: <test name="Test" preserve-order="true"> }dependsOnMethods是您想要的,而不是保留顺序(实际上,dependsonroups建议优于dependsOnMethods,但两者都可以工作)
dependsOnMethods
如果我只是从包中将其作为TestNG测试运行,那么测试在100%的时间内运行良好
当我将测试包含在TestNG套件中时,这些方法会无序运行。是的,我正在使用:
<test name="Test" preserve-order="true">
}
dependsOnMethods
是您想要的,而不是保留顺序
(实际上,dependsonroups
建议优于dependsOnMethods
,但两者都可以工作)
如果您有一个小测试用例显示问题,请发布它
@Test(groups={ "Administration"})
public class RoleCrudTest extends AbstractIntegrationTest
{
protected static SeleniumActionHelper action;
@Test
public void inactiveRole() throws Exception
{
SeleniumHelper helper = new SeleniumHelper();
action = new SeleniumActionHelper(driver);
helper.login();
String roleUrl = navigateToUrl("role/roles.xhtml");
driver.get(roleUrl);
assertEquals("Role:", findElementBySelector("span.portletButtonHeader").getText());
WebElement roleName = findElementById("roleName");
assertFalse(roleName.isEnabled());
WebElement deptId = findElementById("deptid");
assertFalse(deptId.isEnabled());
}
@Test(dependsOnMethods = "inactiveRole")
public void createRole() throws Exception
{
WebElement addButton = findElementById("add");
addButton.click();
waitUntilAjaxRequestCompletes();
WebElement roleName = findElementById("roleName");
roleName.click();
roleName.sendKeys("AAAAAAAA");
WebElement deptId = findElementByXpath("(//button[@type='button'])[3]");
deptId.click();
WebElement dept = findElementByXpath("//div[@id='department_panel']/ul/li[2]");
dept.click();
WebElement checkbox = findElementByXpath("//li[@id='privileges:1']/div/span/div/div");
checkbox.click();
Thread.sleep(1000);
WebElement save = findElementById("save");
save.click();
assertEquals("Role saved successfully", findElementBySelector("div.ui-growl-message > p").getText());
}
@Test(dependsOnMethods = "createRole")
public void editUndo() throws Exception
{
Thread.sleep(1000);
WebElement tableSort = findElementByXpath("//th[@id='tableSection:rolesListWrapped:j_idt85']/div/span[2]");
tableSort.click();
Thread.sleep(1000);
WebElement createdRole = findElementByXpath("//tbody[@id='tableSection:rolesListWrapped_data']/tr[1]/td/div");
createdRole.click();
Thread.sleep(1000);
WebElement roleName = findElementById("roleName");
roleName.click();
roleName.clear();
roleName.sendKeys("edited");
WebElement deptId = findElementByXpath("(//button[@type='button'])[3]");
deptId.click();
WebElement dept = findElementByXpath("//div[@id='department_panel']/ul/li[3]");
dept.click();
WebElement checkbox = findElementByXpath("//li[@id='privileges:1']/div/span/div/div/span");
checkbox.click();
WebElement checkbox2 = findElementByXpath("//li[@id='privileges:0']/div/span/div/div");
checkbox2.click();
Thread.sleep(1000);
WebElement undo = findElementById("cancel");
undo.click();
String text = findElementById("roleName").getAttribute("value");
String oldtext = "AAAAAAAA";
assertTrue(text.equals(oldtext));
}
@Test(dependsOnMethods = "editUndo")
public void editRole() throws Exception
{
Thread.sleep(1000);
WebElement createdRole = findElementByXpath("//tbody[@id='tableSection:rolesListWrapped_data']/tr[1]/td/div");
createdRole.click();
Thread.sleep(1000);
WebElement roleName = findElementById("roleName");
roleName.click();
roleName.clear();
roleName.sendKeys("AAAAAAAAedited");
WebElement deptId = findElementByXpath("(//button[@type='button'])[3]");
deptId.click();
WebElement dept = findElementByXpath("//div[@id='department_panel']/ul/li[3]");
dept.click();
WebElement checkbox = findElementByXpath("//li[@id='privileges:1']/div/span/div/div/span");
checkbox.click();
WebElement checkbox2 = findElementByXpath("//li[@id='privileges:0']/div/span/div/div");
checkbox2.click();
Thread.sleep(1000);
WebElement save = findElementById("save");
save.click();
assertEquals("Role saved successfully", findElementBySelector("div.ui-growl-message > p").getText());
}
@Test(dependsOnMethods = "editRole")
public void deleteRole() throws Exception
{
Thread.sleep(1000);
WebElement deleteButton = findElementById("tableSection:delete");
deleteButton.click();
WebElement deleteConfirm = findElementById("confirmDelete:yes");
deleteConfirm.click();
Thread.sleep(500);
assertEquals("Role deleted successfully", findElementBySelector("div.ui-growl-message > p").getText());
waitUntilAjaxRequestCompletes();
}