Skip to content

Commit 2f79118

Browse files
committed
Rework our new SeCore test runner.
This allows us to implement methods that wrap the output of the next step to be executed (eg. "assertFailureOnNext")
1 parent eb31e47 commit 2f79118

File tree

7 files changed

+381
-209
lines changed

7 files changed

+381
-209
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.server.htmlrunner;
19+
20+
21+
public class CoreRunnerError extends Error {
22+
public CoreRunnerError(String message, Object... args) {
23+
super(String.format(message, args));
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.server.htmlrunner;
19+
20+
import com.thoughtworks.selenium.Selenium;
21+
22+
public interface CoreStep {
23+
Object execute(Selenium selenium);
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.server.htmlrunner;
19+
20+
import java.util.Iterator;
21+
import java.util.List;
22+
23+
interface CoreStepFactory {
24+
CoreStep create(Iterator<List<String>> remainingSteps, String locator, String value);
25+
}

java/server/src/org/openqa/selenium/server/htmlrunner/CoreTestCase.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,24 @@
2020

2121
import com.google.common.base.Preconditions;
2222
import com.google.common.collect.ImmutableList;
23+
import com.google.common.collect.ImmutableMap;
2324

2425
import com.thoughtworks.selenium.Selenium;
2526
import com.thoughtworks.selenium.SeleniumException;
2627

2728
import org.openqa.selenium.JavascriptExecutor;
2829
import org.openqa.selenium.WebDriver;
2930

31+
import java.util.Iterator;
3032
import java.util.List;
3133

3234
public class CoreTestCase {
3335

36+
private static final ImmutableMap<String, CoreStepFactory> STEP_FACTORY =
37+
ImmutableMap.<String, CoreStepFactory>builder()
38+
.putAll(new ReflectivelyDiscoveredSteps().get())
39+
.putAll(new NonReflectiveSteps().get())
40+
.build();
3441
private String url;
3542

3643
public CoreTestCase(String url) {
@@ -43,21 +50,18 @@ public void run(Results results, WebDriver driver, Selenium selenium) {
4350
driver.get(url);
4451
}
4552

46-
List<CoreTestStep> steps = findCommands(driver);
47-
for (CoreTestStep step : steps) {
53+
List<CoreStep> steps = findCommands(driver);
54+
for (CoreStep step : steps) {
4855
try {
49-
step.run(results, driver, selenium);
50-
Thread.sleep(2000);
56+
step.execute(selenium);
5157
} catch (SeleniumException e) {
5258
results.addTestFailure();
5359
return;
54-
} catch (InterruptedException e) {
55-
e.printStackTrace();
5660
}
5761
}
5862
}
5963

60-
private List<CoreTestStep> findCommands(WebDriver driver) {
64+
private List<CoreStep> findCommands(WebDriver driver) {
6165
// Let's just run and hide in the horror that is JS for the sake of speed.
6266
List<List<String>> rawSteps = (List<List<String>>) ((JavascriptExecutor) driver).executeScript(
6367
"var toReturn = [];\n" +
@@ -73,9 +77,14 @@ private List<CoreTestStep> findCommands(WebDriver driver) {
7377
"}\n" +
7478
"return toReturn;");
7579

76-
ImmutableList.Builder<CoreTestStep> steps = ImmutableList.builder();
77-
for (List<String> rawStep: rawSteps) {
78-
steps.add(new CoreTestStep(rawStep.get(0), rawStep.get(1), rawStep.get(2)));
80+
ImmutableList.Builder<CoreStep> steps = ImmutableList.builder();
81+
Iterator<List<String>> stepIterator = rawSteps.iterator();
82+
while (stepIterator.hasNext()) {
83+
List<String> step = stepIterator.next();
84+
if (!STEP_FACTORY.containsKey(step.get(0))) {
85+
throw new SeleniumException("Unknown command: " + step.get(0));
86+
}
87+
steps.add(STEP_FACTORY.get(step.get(0)).create(stepIterator, step.get(1), step.get(2)));
7988
}
8089
return steps.build();
8190
}

java/server/src/org/openqa/selenium/server/htmlrunner/CoreTestStep.java

Lines changed: 0 additions & 199 deletions
This file was deleted.

0 commit comments

Comments
 (0)