Skip to content

Commit f5dffeb

Browse files
committed
Start migrating classes from an internal package to com.thoughtworks.selenium.webdriven
The idea is to try and make the eventual hiving off of the legacy RC package in Selenium 3.0 a simpler proposition.
1 parent 94a9aff commit f5dffeb

File tree

107 files changed

+343
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+343
-85
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2007-2009 Selenium committers
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package com.thoughtworks.selenium.webdriven;
18+
19+
import com.thoughtworks.selenium.SeleniumException;
20+
21+
import org.openqa.selenium.WebDriver;
22+
import org.openqa.selenium.WebDriverException;
23+
24+
public abstract class SeleneseCommand<T> {
25+
26+
private long defaultTimeout;
27+
28+
public T apply(WebDriver driver, String[] args) {
29+
try {
30+
switch (args.length) {
31+
case 0:
32+
return handleSeleneseCommand(driver, null, null);
33+
34+
case 1:
35+
return handleSeleneseCommand(driver, args[0], null);
36+
37+
case 2:
38+
return handleSeleneseCommand(driver, args[0], args[1]);
39+
40+
default:
41+
throw new SeleniumException("Too many arguments! " + args.length);
42+
}
43+
} catch (WebDriverException e) {
44+
throw new SeleniumException(e.getMessage(), e);
45+
}
46+
}
47+
48+
public void setDefaultTimeout(long defaultTimeout) {
49+
this.defaultTimeout = defaultTimeout;
50+
}
51+
52+
protected long getTimeout(String timeout) {
53+
return "".equals(timeout) ? defaultTimeout : Long.valueOf(timeout);
54+
}
55+
56+
protected abstract T handleSeleneseCommand(WebDriver driver, String locator, String value);
57+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
java_library(name = "emulation-api",
3+
srcs = [
4+
"SeleneseCommand.java",
5+
],
6+
deps = [
7+
"//java/client/src/com/thoughtworks/selenium:api",
8+
"//java/client/src/org/openqa/selenium:webdriver-api",
9+
])
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2007-2009 Selenium committers
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package com.thoughtworks.selenium.webdriven.commands;
18+
19+
import com.thoughtworks.selenium.SeleniumException;
20+
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
21+
22+
import org.openqa.selenium.WebDriver;
23+
24+
public class Timer {
25+
private volatile long timeout;
26+
private boolean stopped;
27+
28+
public Timer(long timeout) {
29+
this.timeout = timeout;
30+
}
31+
32+
public <T> T run(SeleneseCommand<T> command, WebDriver driver, String[] args) {
33+
if (stopped) {
34+
throw new IllegalStateException("Timer has already been stopped");
35+
}
36+
37+
command.setDefaultTimeout(timeout);
38+
39+
long start = System.currentTimeMillis();
40+
41+
T value = command.apply(driver, args);
42+
43+
long duration = System.currentTimeMillis() - start;
44+
45+
if (duration > timeout) {
46+
throw new SeleniumException("Timed out waiting for action to finish");
47+
}
48+
49+
return value;
50+
}
51+
52+
public void setTimeout(long timeout) {
53+
this.timeout = timeout;
54+
}
55+
56+
public void stop() {
57+
this.stopped = true;
58+
}
59+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
java_library(name = "api",
3+
srcs = [
4+
"Timer.java",
5+
],
6+
deps = [
7+
"//java/client/src/com/thoughtworks/selenium/webdriven:emulation-api",
8+
])

java/client/src/org/openqa/selenium/WebDriverCommandProcessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import com.thoughtworks.selenium.CommandProcessor;
2424
import com.thoughtworks.selenium.SeleniumException;
25+
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
26+
import com.thoughtworks.selenium.webdriven.commands.Timer;
2527

2628
import org.openqa.selenium.internal.WrapsDriver;
2729
import org.openqa.selenium.internal.seleniumemulation.*;

java/client/src/org/openqa/selenium/internal/seleniumemulation/AddLocationStrategy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.openqa.selenium.internal.seleniumemulation;
1818

19+
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
20+
1921
import org.openqa.selenium.WebDriver;
2022

2123
public class AddLocationStrategy extends SeleneseCommand<Void> {

java/client/src/org/openqa/selenium/internal/seleniumemulation/AddSelection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.openqa.selenium.internal.seleniumemulation;
1818

19+
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
20+
1921
import org.openqa.selenium.WebDriver;
2022

2123
public class AddSelection extends SeleneseCommand<Void> {

java/client/src/org/openqa/selenium/internal/seleniumemulation/AllowNativeXPath.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.openqa.selenium.internal.seleniumemulation;
1818

1919
import com.thoughtworks.selenium.SeleniumException;
20+
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
2021

2122
import org.openqa.selenium.WebDriver;
2223

java/client/src/org/openqa/selenium/internal/seleniumemulation/AltKeyDown.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package org.openqa.selenium.internal.seleniumemulation;
2020

21+
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
22+
2123
import org.openqa.selenium.WebDriver;
2224

2325
public class AltKeyDown extends SeleneseCommand<Void> {

java/client/src/org/openqa/selenium/internal/seleniumemulation/AltKeyUp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package org.openqa.selenium.internal.seleniumemulation;
2020

21+
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
22+
2123
import org.openqa.selenium.WebDriver;
2224

2325
public class AltKeyUp extends SeleneseCommand<Void> {

0 commit comments

Comments
 (0)