TestNG和; Selenium:对具有依赖关系的实体执行CRUD操作

时间:2014-07-29 10:29:42

标签: java selenium selenium-webdriver automation testng

我是Selenium和TestNG的新手我无法按顺序执行脚本。 我必须对实体执行CRUD操作,如用户位置设备配置文件< / em>,角色,它们之间有依赖关系。

我为每个操作(我在注释中)创建了一个单独的组,我在每个实体上执行,如 addGroup editGroup deleteGroup 对于上面的每个实体等等。 一些实体依赖于其他实体

添加群组

@Test(dependsOnGroups={"loginGroup"},groups="addGroup")
 public void AddGroup() {}

编辑群组

editGroup依赖于addGroup操作,如下所示

@Test(dependsOnGroups = { "loginGroup","addGroup"}, groups = "editGroup")
 public void editGroup() {}

删除群组

@Test(dependsOnGroups={"loginGroup","addGroup","deleteLocation"},groups="deleteGroup")
 public void deleteGroup() {}

添加位置

AddLocation操作依赖于AddGroup。

@Test(dependsOnGroups = {"loginGroup", "addGroup" }, groups = "addLocation")
 public void addLocation() {}

编辑位置

editLocation依赖于AddLocation

@Test(dependsOnGroups = { "loginGroup","addLocation"}, groups = "editLocation")
 public void editLocation() {}

删除位置

deleteLocation依赖于addLocation操作

@Test(dependsOnGroups={"loginGroup","addLocation"},groups="deleteLocation")
 public void deleteLocation(String locationId) {}

添加角色

@Test(dependsOnGroups = { "loginGroup"}, groups = "addRole",dataProviderClass=AddNewRoleDataProvider.class)
 public void addRole() { }

编辑角色

editRole依赖于addRole

@Test(dependsOnGroups = { "loginGroup","addRole"}, groups = "editRole")
 public void editRole() {}

删除角色

deleteRole依赖于addLocation操作

@Test(dependsOnGroups = { "loginGroup", "addRole", "deleteUser" }, groups = "deleteRole")
 public void deleteRole() { }

添加用户

AddUser操作依赖于AddLocation,AddGroup,AddRole Operations。

@Test(dependsOnGroups = {"loginGroup", "addGroup", "addLocation","addRole"}, groups = "addUser")
 public void AddUser() { }

编辑用户

editUser操作依赖于addUser操作

@Test(dependsOnGroups = { "loginGroup","addUser"}, groups = "editUser")
 public void editUser() { }

删除用户

删除用户操作取决于addUser操作

@Test(dependsOnGroups = { "loginGroup","addUser"}, groups = "deleteUser")
 public void deleteUser(String userId) throws Exception {}

现在我想以套件的形式运行此操作以下是将此脚本作为套件运行的代码

@Test(dependsOnGroups={"addGroup","addLocation","addRole","addUser",
   "editGroup","editLocation","editRole","editUser",
   "deleteUser","deleteLocation","deleteRole","deleteGroup"})
 public void startSuite() {}

当我运行我的套件时,它会在添加User之前删除Location,因此addUser操作会被终止。

1 个答案:

答案 0 :(得分:0)

我认为你有点过于复杂的情况,在课堂上分别对每个实体进行测试会不会更容易?喜欢

@Test(dependsOnGroups = {"loginGroup", "groupCrud", "locationCrud","roleCrud"}, 
       groups = "userCrud")
public TestUserCrudOperations {

    @Test(priority = 0)
    public void addUser() {}

    @Test(priority = 1) 
    public void editUser() {}

    @Test(priority = 2)
    public void deteleUser() {}

   //method with lower priority is executed first

}

通过将测试分成这样的类,您将获得更多可读性和可维护性的代码(并且您将避免过多的组具有困难的依赖性)。