[英]Manage selenium test project
I have general questions about Managing selenium web project, the example is below, my question is how to manage those test cases?(its only 3 for the example, the real number of test cases is more than 1000) 我有关于管理selenium web项目的一般问题,下面是一个例子,我的问题是如何管理那些测试用例?(例子中只有3个,测试用例的实际数量超过1000个)
Did create class for sub tests is good, like class for login and all the tests that related to log in is under this class? 为子测试创建类是否合适,如登录类和所有与登录相关的测试都在此类下?
Did there is an Conventions for writing test cases and manage them? 是否有编写测试用例并管理它们的约定?
Thanks you all. 谢谢大家。
I create class with tests like:
@Test //Test1
public void logInFaildTest() {
GridTest gridTest = new GridTest();
WebDriver webDriver = gridTest.getWebDriver();
String url = gridTest.getUrl();
LoginPage logIn = new LoginPage(webDriver, url);
String userName = "user";
String pass="pass";
logIn.login(userName, pass);
WebElement errorMsg = webDriver.findElement(By.className("dijitToasterContent"));
String actual = errorMsg.getAttribute("innerHTML");
String expected="Incorrect user name or password. Please try again.";
assertEquals(expected, actual);
webDriver.close();
}
@Test
public void loginSucsecc()
{
GridTest gridTest = new GridTest();
String url = gridTest.getUrl();
WebDriver webDriver = gridTest.getWebDriver();
LoginPage logIn = new LoginPage(webDriver, url);
String userName = "user";
String pass="pass";
logIn.login(userName, pass);
String actual = webDriver.getCurrentUrl();
String expected= url+"#lastmile/";
// webDriver.close();
webDriver.quit();
assertEquals(expected, actual);
}
@Test
public void accountLock()
{
GridTest gridTest = new GridTest();
String url = gridTest.getUrl();
WebDriver webDriver = gridTest.getWebDriver();
LoginPage logIn = new LoginPage(webDriver, url);
String userName = "user";
String pass="wrong";
for(int i=0;i<11;i++){
logIn.login(userName, pass);
logIn.clearFileduNamePass();
}
WebElement msg = webDriver.findElement(By.id("dijit__TemplatedMixin_0")); //block message
String actual = msg.getAttribute("innerHTML");
int splitIndex= actual.indexOf(".<");
actual = actual.substring(0, splitIndex);
String expected= "Your account has been locked";
webDriver.quit();
assertEquals(expected, actual);
}
}
Yes what you've done is good only.So that all Login related operations can go into one class so if there is any change we can easily manage that 是的,你所做的只是好的。所有与登录相关的操作都可以进入一个类,所以如果有任何改变,我们可以很容易地管理
Object Maintaenance 对象维护
You can go with Page Object Model(POM) as it is widely used approach and easily manageable one.This is for managing your Objects more like maintaining an Object Repository 您可以使用页面对象模型(POM),因为它是广泛使用的方法和易于管理的方法。这更像是维护对象存储库来管理对象
As you can observe, all we are doing is finding elements and filling values for those elements. 正如您所看到的,我们所做的只是找到元素并为这些元素填充值。
This is a small script. 这是一个小脚本。 Script maintenance looks easy. 脚本维护看起来很简单 But with time test suite will grow. 但随着时间的推移测试套件将会增长 As you add more and more lines to your code, things become tough. 随着您为代码添加越来越多的行,事情变得艰难。
The chief problem with script maintenance is that if 10 different scripts are using the same page element, with any change in that element, you need to change all 10 scripts. 脚本维护的主要问题是,如果10个不同的脚本使用相同的页面元素,并且该元素有任何更改,则需要更改所有10个脚本。 This is time consuming and error prone. 这是耗时且容易出错的。
A better approach to script maintenance is to create a separate class file which would find web elements , fill them or verify them. 更好的脚本维护方法是创建一个单独的类文件,该文件可以找到Web元素,填充它们或验证它们。 This class can be reused in all the scripts using that element. 可以在使用该元素的所有脚本中重用此类。 In future if there is change in the web element , we need to make change in just 1 class file and not 10 different scripts. 将来,如果web元素发生变化,我们需要仅在1个类文件中进行更改,而不是在10个不同的脚本中进行更改。
This approach is called Page Object Model(POM) . 这种方法称为页面对象模型(POM) 。 It helps make code more readable, maintainable, and reusable. 它有助于使代码更具可读性,可维护性和可重用性。
Test Data Maintenance 测试数据维护
The next you've to consider is the test data used to run the test cases with different set of data Test-Driven Approach 接下来要考虑的是用于运行具有不同数据集测试驱动方法的测试用例的测试数据
Same as POM You can create a factory class which will give you set of data whenever required so that when you want to change/modify the data you can simply go to the factory and change it . 与POM相同您可以创建一个工厂类,它将在需要时为您提供数据集,这样当您想要更改/修改数据时,您只需转到工厂并进行更改即可。
For ex you create a class named LoginData
which have functions like getValidCredentials
getRandomCredentials
to get your data. 例如,您创建一个名为LoginData
的类,它具有getValidCredentials
getRandomCredentials
等函数来获取数据。 If your application requires random emailid for each run then you can simply modify the getValidCredentials
part alone It will help you a lot when your application runs mainly on forms or user datas 如果您的应用程序每次运行都需要随机的emailid,那么您可以单独修改getValidCredentials
部分当您的应用程序主要在表单或用户数据上运行时,它会对您有所帮助
Reusable Components 可重复使用的组件
The third thing is the Re-usability of what you've created.You can reuse the validLogin for other scenario's as well 第三件事是您创建的内容的可重用性。您可以将validLogin重用于其他场景
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.