Skip to content

Commit aaef16f

Browse files
committed
Add missing *Selected commands to the core runner
1 parent a59d982 commit aaef16f

File tree

6 files changed

+142
-90
lines changed

6 files changed

+142
-90
lines changed

java/client/src/com/thoughtworks/selenium/webdriven/BUCK

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ java_library(name = 'webdriven',
2929
],
3030
exported_deps = [
3131
':emulation-api',
32+
'//java/client/src/com/thoughtworks/selenium/webdriven/commands:commands',
3233
],
3334
deps = [
3435
'//java/client/src/com/thoughtworks/selenium:selenium',
35-
'//java/client/src/com/thoughtworks/selenium/webdriven/commands:commands',
3636
'//java/client/src/org/openqa/selenium:selenium',
3737
'//third_party/java/guava:guava',
3838
],
@@ -41,6 +41,7 @@ java_library(name = 'webdriven',
4141
'//java/client/test/com/thoughtworks/selenium/...',
4242
'//java/server/src/com/thoughtworks/selenium/webdriven:rc-emulation-servlet',
4343
'//java/server/src/org/openqa/grid/selenium:classes',
44+
'//java/server/src/org/openqa/selenium/server/htmlrunner:htmlrunner',
4445
],
4546
)
4647

java/client/src/com/thoughtworks/selenium/webdriven/commands/SeleniumSelect.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ public class SeleniumSelect {
3636
private final WebDriver driver;
3737
private final WebElement select;
3838

39-
public SeleniumSelect(JavascriptLibrary library, ElementFinder finder, WebDriver driver,
40-
String locator) {
39+
public SeleniumSelect(
40+
JavascriptLibrary library,
41+
ElementFinder finder,
42+
WebDriver driver,
43+
String locator) {
4144
this.driver = driver;
4245

4346
findOption =
44-
"return (" + library.getSeleniumScript("findOption.js") + ").apply(null, arguments)";
47+
"return (" + library.getSeleniumScript("findOption.js") + ").apply(null, arguments)";
4548

4649
select = finder.findElement(driver, locator);
4750
if (!"select".equals(select.getTagName().toLowerCase())) {
@@ -94,7 +97,7 @@ public List<WebElement> getSelectedOptions() {
9497
return toReturn;
9598
}
9699

97-
private WebElement findOption(String optionLocator) {
100+
public WebElement findOption(String optionLocator) {
98101
return (WebElement) ((JavascriptExecutor) driver)
99102
.executeScript(findOption, select, optionLocator);
100103
}

java/server/src/org/openqa/selenium/server/htmlrunner/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ java_library(
1111
srcs = glob(['*.java']),
1212
deps = [
1313
'//java/client/src/com/thoughtworks/selenium:leg-rc',
14+
'//java/client/src/com/thoughtworks/selenium/webdriven:webdriven',
1415
'//java/client/src/org/openqa/selenium:selenium',
1516
'//java/client/src/org/openqa/selenium/chrome:chrome',
1617
'//java/client/src/org/openqa/selenium/edge:edge',

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424

2525
import com.thoughtworks.selenium.Selenium;
2626
import com.thoughtworks.selenium.SeleniumException;
27+
import com.thoughtworks.selenium.webdriven.ElementFinder;
28+
import com.thoughtworks.selenium.webdriven.JavascriptLibrary;
29+
import com.thoughtworks.selenium.webdriven.commands.SeleniumSelect;
30+
31+
import org.openqa.selenium.WebElement;
32+
import org.openqa.selenium.internal.WrapsDriver;
2733

2834
import java.util.logging.Logger;
2935

@@ -50,6 +56,44 @@ private static ImmutableMap<String, CoreStepFactory> build() {
5056
steps.put("verifyErrorOnNext", verifyNextCommandFails);
5157
steps.put("verifyFailureOnNext", verifyNextCommandFails);
5258

59+
class SelectedOption implements CoreStep {
60+
61+
private final String locator;
62+
private final String value;
63+
private final NextStepDecorator onFailure;
64+
65+
public SelectedOption(String locator, String value, NextStepDecorator onFailure) {
66+
this.locator = locator;
67+
this.value = value;
68+
this.onFailure = onFailure;
69+
}
70+
71+
@Override
72+
public NextStepDecorator execute(Selenium selenium, TestState state) {
73+
JavascriptLibrary library = new JavascriptLibrary();
74+
ElementFinder finder = new ElementFinder(library);
75+
SeleniumSelect select = new SeleniumSelect(
76+
library,
77+
finder,
78+
((WrapsDriver) selenium).getWrappedDriver(),
79+
locator);
80+
81+
WebElement element = select.findOption(value);
82+
if (element == null) {
83+
return onFailure;
84+
}
85+
return NextStepDecorator.IDENTITY;
86+
}
87+
}
88+
89+
steps.put(
90+
"assertSelected",
91+
((locator, value) -> new SelectedOption(locator, value, NextStepDecorator.ASSERTION_FAILED)));
92+
steps.put(
93+
"verifySelected",
94+
((locator, value) ->
95+
new SelectedOption(locator, value, NextStepDecorator.VERIFICATION_FAILED)));
96+
5397
steps.put("echo", ((locator, value) -> (selenium, state) -> {
5498
LOG.info(locator);
5599
return NextStepDecorator.IDENTITY;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public String expand(String toExpand) {
7979
lastEnd = matcher.end();
8080
}
8181

82+
// Now append the last part of the input
83+
toReturn.append(toExpand.substring(lastEnd));
84+
8285
return toReturn.toString();
8386
}
8487
}

0 commit comments

Comments
 (0)