问题
In a data-driven framework, we use Selenium along with TestNG to run multiple tests in parallel. How can the same be implemented in a keyword-driven framework?
In data-driven approach we can define every test case as a separate method and therefore we are able to command TestNG via annotations which methods to run and how many to run in parallel.
In keyword-driven approach, every test case is a separate Excel Sheet and multiple excel sheets in the same workbook make a test suite. How can these excel sheets/test cases be annotated/referred so as to run in parallel similar to the execution structure and process in data-driven framework?
One lame solution I thought of was a hybrid approach wherein creating methods which would call the excel sheet.
For eg.:
@Test
public void TestCase_001() {
// Read the keyword driven test case
// XLS_WorkbookName - The Excel Workbook or Test Suite containing multiple Test Cases
// XLS_SheetName - The Excel Sheet containing set of rows each of which contains ID of element, Operation to be performed and data to be used
ReadAndExecuteTestCase(XLS_WorkbookName_XYZ, XLS_SheetName_ABC);
}
@Test
public void TestCase_002() {
// Read the keyword driven test case
// XLS_WorkbookName - The Excel Workbook or Test Suite containing multiple Test Cases
// XLS_SheetName - The Excel Sheet containing set of rows each of which contains ID of element, Operation to be performed and data to be used
ReadAndExecuteTestCase(XLS_WorkbookName_ABC, XLS_SheetName_XYZ);
}
I'm not sure if they above example is the appropriate way to go about it. Requesting suggestions to the same. Thanks in advance.
回答1:
One solution can be :
- Have a master sheet of cases to execute, which acts as your suite.
- Have your dataprovider read this master sheet and have a single @Test method which takes in the arguments of the testcase data. This testcase basically reads the steps and executes - something like your ReadAnExecureTestCase method.
- Make this dataprovider parallel and control using dataprovider thread count.
来源:https://stackoverflow.com/questions/26623425/executing-parallel-tests-in-a-selenium-keyword-driven-framework