关键字驱动的框架和Selenium网格以及单个测试用例的报告
我已经使用Selenium WebDriver和Java开发了一个关键字驱动的框架。基本上,我已经开发了一个主TC表,其中它以“是”的运行模式读取TCs,然后转到测试步骤表,读取关键字,并根据这些关键字执行操作 我正在使用驱动程序脚本来阅读这些测试用例关键字驱动的框架和Selenium网格以及单个测试用例的报告,selenium,selenium-webdriver,keyword,selenium-grid,Selenium,Selenium Webdriver,Keyword,Selenium Grid,我已经使用Selenium WebDriver和Java开发了一个关键字驱动的框架。基本上,我已经开发了一个主TC表,其中它以“是”的运行模式读取TCs,然后转到测试步骤表,读取关键字,并根据这些关键字执行操作 我正在使用驱动程序脚本来阅读这些测试用例 public class DriverScript { @Test public void startExecution() throws Exception{ //public static void main(Str
public class DriverScript {
@Test
public void startExecution() throws Exception{
//public static void main(String[] args) throws Exception {
excelUtilities eu = new excelUtilities();
Properties gldata = new Properties();
InputStream input = new FileInputStream("src/executionEngine/config.properties");
gldata.load(input);
List<List<String>> testcases = new ArrayList<List<String>>();
testcases = eu.getTestCases(gldata.getProperty("WB_PATH_TESTS"), gldata.getProperty("WB_PATH_TESTS_SHEET"));
//System.out.println(testcases);
DriverScript.prepareKeywords(testcases);
}
现在我想使用selenium网格并行运行这些测试用例。我在stackoverflow上找到了两篇关于这件事的帖子
但在这篇文章中没有提到如何实现这一点
这里提出了一个解决方案,但报告是作为一个通过或失败的测试用例生成的
我在driverscript中为该方法添加了@Test注释,该方法读取上述测试用例
public class DriverScript {
@Test
public void startExecution() throws Exception{
//public static void main(String[] args) throws Exception {
excelUtilities eu = new excelUtilities();
Properties gldata = new Properties();
InputStream input = new FileInputStream("src/executionEngine/config.properties");
gldata.load(input);
List<List<String>> testcases = new ArrayList<List<String>>();
testcases = eu.getTestCases(gldata.getProperty("WB_PATH_TESTS"), gldata.getProperty("WB_PATH_TESTS_SHEET"));
//System.out.println(testcases);
DriverScript.prepareKeywords(testcases);
}
那么,当我们有关键字驱动的框架时,如何并行运行测试用例呢
我想的唯一解决办法是,第二篇文章的问题部分提到的方法,比如为每个测试用例创建单独的方法,并阅读测试用例步骤
关于如何在selenium网格上运行关键字驱动的框架,是否有其他方法
谢谢。使用TestNg中的DataProvider选项运行测试。因此,每个数据将被视为分离测试。< /P> 将数据提供程序指向@Factory选项,以便为每个数据创建新实例。现在我们可以使用
parallel=intance
运行测试。因此,每个测试用例将在不同的线程中并行运行
我们可以按如下方式重写您的驱动程序脚本
public class DriverScript {
List<String> testcase;
@Factory(dataProvider = "testCases")
public DriverScript(List<String> testcase) {
this.testcase = testcase;
}
@Test
public void runTestCase() {
// change this method run single with List<String>. Previously you passed List<List<String>>
DriverScript.prepareKeywords(testcase);
}
@DataProvider
public Object[][] testCases(ITestContext context) throws InterruptedException {
excelUtilities eu = new excelUtilities();
Properties gldata = new Properties();
InputStream input = new FileInputStream("src/executionEngine/config.properties");
gldata.load(input);
List<List<String>> testcases = new ArrayList<List<String>>();
testcases = eu.getTestCases(gldata.getProperty("WB_PATH_TESTS"), gldata.getProperty("WB_PATH_TESTS_SHEET"));
List<List<String>> testcases = new ArrayList<>();
Object[][] testCasedata= new Object[testcases.size()][1];
for (int i = 0; i < testcases.size() ; i++) {
testCasedata[i][0]=testcases.get(i);
}
return testCasedata;
公共类驱动程序脚本{
列出测试用例;
@工厂(dataProvider=“testCases”)
公共驱动程序脚本(列表测试用例){
this.testcase=testcase;
}
@试验
public void runTestCase(){
//更改此方法使用列表运行single。以前您传递了列表
DriverScript.prepareKeywords(testcase);
}
@数据提供者
公共对象[][]测试用例(ITestContext上下文)引发InterruptedException{
excelUtilities eu=新的excelUtilities();
属性gldata=新属性();
InputStream输入=新文件InputStream(“src/executionEngine/config.properties”);
gldata.load(输入);
List testcases=new ArrayList();
testcases=eu.getTestCases(gldata.getProperty(“WB_路径_测试”),gldata.getProperty(“WB_路径_测试表”);
List testcases=new ArrayList();
Object[]testCasedata=新对象[testcases.size()][1];
对于(int i=0;i
}
要使用parallel=实例运行上述测试,我们必须像下面那样创建testuite xml,并使用此xml套件运行testng
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="KeywordDrivenSuite" thread-count="2" parallel="instances"
preserve-order="true" configfailurepolicy="continue">
<test name="KeywordDrivenTest">
<classes>
<class
name="com.package.DriverScript" />
</classes>
</test>
</suite>
以下是我如何尝试它的,它正在工作
@DataProvider(name = "maintestcases",parallel = true)
public static String[][] startexecution() throws Exception{
excelUtilities eu = new excelUtilities();
Properties gldata = new Properties();
InputStream input = new FileInputStream("src/executionEngine/config.properties");
gldata.load(input);
List<List<String>> testcases = new ArrayList<List<String>>();
testcases = eu.getTestCases(gldata.getProperty("WB_PATH_TESTS"), gldata.getProperty("WB_PATH_TESTS_SHEET"));
int no_test_cases = testcases.size();
String testcasesobject[][] = new String[no_test_cases][3];
for(int i=0; i<testcases.size(); i++) {
testcasesobject[i][0] = testcases.get(i).get(0);
testcasesobject[i][1] = testcases.get(i).get(1);
testcasesobject[i][2] = testcases.get(i).get(2);
}
System.out.println(Arrays.toString(testcasesobject));
return testcasesobject;
}
@Test(dataProvider = "maintestcases")
public static void prepareKeywords(String testcase, String wbbook, String sheet) throws IOException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, InterruptedException {
Properties gldata = new Properties();
InputStream input = new FileInputStream("src/executionEngine/config.properties");
gldata.load(input);
//int total_testcases = testcases.size();
excelUtilities ecu = new excelUtilities();
LogUtilities.startTestCase(testcase);
List<String> keywords = new ArrayList<String>();
keywords = ecu.getKeywordsFromTestCase(testcase,gldata.getProperty("WB_PATH_TEST_CASES")+wbbook+".xlsx", sheet);
getDependencies(keywords);
}
@DataProvider(name=“maintestcases”,parallel=true)
公共静态字符串[][]startexecution()引发异常{
excelUtilities eu=新的excelUtilities();
属性gldata=新属性();
InputStream输入=新文件InputStream(“src/executionEngine/config.properties”);
gldata.load(输入);
List testcases=new ArrayList();
testcases=eu.getTestCases(gldata.getProperty(“WB_路径_测试”),gldata.getProperty(“WB_路径_测试表”);
int no_test_cases=testcases.size();
字符串testcasesobject[][]=新字符串[无测试用例][3];
对于(int i=0;i
请检查此解决方案,并让我知道这是否可以
谢谢。您也可以在不使用xml文件的情况下运行测试。请使用@Navarasu提供的DriverScript,并从下面的函数执行它们
void executionDriver(){
TestNG test = new TestNG();
XmlSuite suite = new XmlSuite();
suite.setName("KeywordDrivenSuite");
XmlTest xmlTest = new XmlTest(suite);
xmlTest.setName("KeywordDrivenTest");
List<XmlClass> xmlClasses = new ArrayList<XmlClass> ();
String packageName = "com.package.DriverScript";
XmlClass xmlclass = new XmlClass(packageName);
xmlClasses.add(xmlclass);
xmlTest.setXmlClasses(xmlClasses);
List<XmlTest> testList = new ArrayList<XmlTest>();
testList.add(xmlTest);
suite.setTests(testList);
List<XmlSuite> suiteList = new ArrayList<XmlSuite>();
suiteList.add(suite);
test.setXmlSuites(suiteList);
test.test.setThreadCount(3);//Thread count can be controlled from properties file also.
test.run();
}
void executionDriver(){
TestNG test=新的TestNG();
XmlSuite=newxmlsuite();
suite.setName(“关键字驱动网站”);
XmlTest XmlTest=新的XmlTest(套件);
setName(“关键字驱动测试”);
List xmlClasses=newarraylist();
字符串packageName=“com.package.DriverScript”;
XmlClass XmlClass=新的XmlClass(packageName);
添加(xmlclass);
setXmlClasses(xmlClasses);
List testList=new ArrayList();
testList.add(xmlTest);
setTests(testList);
List suiteList=new ArrayList();
suiteList.add(套件);
test.setXmlSuite(suiteList);
test.test.setThreadCount(3);//也可以从属性文件控制线程数。
test.run();
}
您是否尝试过这些方法中的任何一种?如果是,您面临的问题是什么?嗨,阿披舍克,正如第二篇文章中提到的,我已经为读取主要测试用例的方法创建了@Test注释。但是它在生成报告时通过了一个测试用例,即使我们有两个测试用例。这可能是我对解决方案的理解it’错了。我想在2个TCs通过或失败时获取报告。您能告诉我,我们是否可以不为每个测试用例创建单独的方法来完成这项工作吗?感谢Navarasu提供了伟大的解决方案。我以相同的方式尝试了它,但使用dataprovider parallel属性作为true和在testng配置文件中使用它时略有不同使用data provider thread count=“2”和parallel=“methods”。但我认为您的解决方案要好得多。我无法在注释部分发布代码,因此我会将其作为答案发布。请检查它,并告知我是否有任何错误。这对您的情况没有问题。我知道此选项。请注意@DataProvider(name=“maintestcases”,平行=真)将有不同于主线程池的线程池。因此,如果我们将驱动程序维护为线程级缓存,则此解决方案将不起作用。谢谢Navarasu。我认为最好使用您的选项,我将使用该选项。但当我们使用dataprovider并行运行时,log4j面临另一个问题。请您在下面的位置,让我知道
void executionDriver(){
TestNG test = new TestNG();
XmlSuite suite = new XmlSuite();
suite.setName("KeywordDrivenSuite");
XmlTest xmlTest = new XmlTest(suite);
xmlTest.setName("KeywordDrivenTest");
List<XmlClass> xmlClasses = new ArrayList<XmlClass> ();
String packageName = "com.package.DriverScript";
XmlClass xmlclass = new XmlClass(packageName);
xmlClasses.add(xmlclass);
xmlTest.setXmlClasses(xmlClasses);
List<XmlTest> testList = new ArrayList<XmlTest>();
testList.add(xmlTest);
suite.setTests(testList);
List<XmlSuite> suiteList = new ArrayList<XmlSuite>();
suiteList.add(suite);
test.setXmlSuites(suiteList);
test.test.setThreadCount(3);//Thread count can be controlled from properties file also.
test.run();
}