|
8 | 8 | import java.util.stream.Collectors; |
9 | 9 |
|
10 | 10 | import org.json.simple.JSONObject; |
11 | | -import org.openqa.selenium.WebDriver; |
12 | 11 |
|
13 | 12 | public class LazyInitWebDriverIterator implements Iterator<Object[]> { |
14 | 13 | private final String testMethodName; |
15 | 14 | private final List<JSONObject> platforms; |
16 | 15 | private final List<Object[]> testParams; |
17 | | - private final boolean createManagedWebDriver; |
18 | | - private int paramIdx = 0; |
| 16 | + private int paramIndex = 0; |
19 | 17 |
|
20 | | - public LazyInitWebDriverIterator(Boolean createManagedWebDriver, Object[][] testParams) { |
| 18 | + public LazyInitWebDriverIterator(Object[][] testParams) { |
21 | 19 | this.testMethodName = ""; |
22 | 20 | this.platforms = WebDriverFactory.getInstance().getPlatforms(); |
23 | | - this.createManagedWebDriver = createManagedWebDriver; |
24 | 21 | List<Object[]> testParamsList = new ArrayList(); |
25 | 22 | if (testParams != null) { |
26 | 23 | testParamsList = (List)Arrays.stream(testParams).collect(Collectors.toList()); |
27 | 24 | } |
28 | 25 |
|
| 26 | + //Create list of combinations of Scenarios and Platforms |
29 | 27 | this.testParams = this.populateTestParams((List)testParamsList); |
30 | 28 | } |
31 | 29 |
|
32 | 30 | private List<Object[]> populateTestParams(List<Object[]> testParams) { |
33 | | - int idx = 0; |
| 31 | + int index = 0; |
34 | 32 | ArrayList tempTestParams = new ArrayList(); |
35 | 33 |
|
36 | 34 | do { |
37 | | - Object[] testParam = (Object[])testParams.get(idx); |
| 35 | + Object[] testParam = (Object[])testParams.get(index); |
38 | 36 | if (testParam == null) { |
39 | 37 | testParam = new Object[0]; |
40 | 38 | } |
41 | 39 |
|
42 | | - Iterator var5 = this.platforms.iterator(); |
| 40 | + Iterator platformsIterator = this.platforms.iterator(); |
43 | 41 |
|
44 | | - while(var5.hasNext()) { |
45 | | - JSONObject platform = (JSONObject)var5.next(); |
| 42 | + while(platformsIterator.hasNext()) { |
| 43 | + JSONObject platform = (JSONObject)platformsIterator.next(); |
46 | 44 | Object[] paramsWithPlatform = Arrays.copyOf(testParam, testParam.length + 1); |
47 | 45 | paramsWithPlatform[paramsWithPlatform.length - 1] = platform; |
48 | 46 | tempTestParams.add(paramsWithPlatform); |
49 | 47 | } |
50 | 48 |
|
51 | | - ++idx; |
52 | | - } while(idx < testParams.size()); |
| 49 | + ++index; |
| 50 | + } while(index < testParams.size()); |
53 | 51 |
|
54 | 52 | return tempTestParams; |
55 | 53 | } |
56 | 54 |
|
57 | 55 | public boolean hasNext() { |
58 | | - return this.paramIdx < this.testParams.size(); |
| 56 | + return this.paramIndex < this.testParams.size(); |
59 | 57 | } |
60 | 58 |
|
61 | 59 | public Object[] next() { |
62 | | - if (this.paramIdx >= this.testParams.size()) { |
| 60 | + if (this.paramIndex >= this.testParams.size()) { |
63 | 61 | throw new NoSuchElementException("No More Platforms configured to create WebDriver for."); |
64 | 62 | } else { |
65 | | - Object[] methodTestParams = (Object[])this.testParams.get(this.paramIdx++); |
| 63 | + Object[] methodTestParams = (Object[])this.testParams.get(this.paramIndex++); |
66 | 64 | if (methodTestParams[methodTestParams.length - 1] instanceof JSONObject) { |
67 | 65 | JSONObject platform = (JSONObject)methodTestParams[methodTestParams.length - 1]; |
68 | | - if (this.createManagedWebDriver) { |
69 | | - ManagedWebDriver managedWebDriver = new ManagedWebDriver(this.testMethodName, platform); |
70 | | - methodTestParams[methodTestParams.length - 1] = managedWebDriver; |
71 | | - } else { |
72 | | - WebDriver webDriver = WebDriverFactory.getInstance().createWebDriverForPlatform(platform, this.testMethodName); |
73 | | - methodTestParams[methodTestParams.length - 1] = webDriver; |
74 | | - } |
| 66 | + ManagedWebDriver managedWebDriver = new ManagedWebDriver(this.testMethodName, platform); |
| 67 | + methodTestParams[methodTestParams.length - 1] = managedWebDriver; |
75 | 68 | } |
76 | | - |
| 69 | + //return an Object array consisting PickleWrapper, FeatureWrapper and ManagedWebDriver |
77 | 70 | return methodTestParams; |
78 | 71 | } |
79 | 72 | } |
|
0 commit comments