From 63325149c175fbdff0cba16da75ce69f8ca24f53 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Sat, 20 Apr 2013 21:54:31 +0400 Subject: [PATCH] Removing SelenseBackedWebDriver --- Rakefile | 2 +- .../selenium/SeleneseCommandExecutor.java | 262 ------------------ .../client/src/org/openqa/selenium/build.desc | 10 - .../selenesedriver/AbstractElementFinder.java | 99 ------- .../internal/selenesedriver/ClearElement.java | 28 -- .../internal/selenesedriver/ClickElement.java | 31 --- .../internal/selenesedriver/Close.java | 47 ---- .../selenesedriver/ElementFunction.java | 40 --- .../selenesedriver/ExecuteAsyncScript.java | 47 ---- .../selenesedriver/ExecuteScript.java | 36 --- .../internal/selenesedriver/FindElement.java | 47 ---- .../internal/selenesedriver/FindElements.java | 54 ---- .../selenesedriver/GetActiveElement.java | 43 --- .../selenesedriver/GetCurrentUrl.java | 28 -- .../selenesedriver/GetElementAttribute.java | 39 --- .../selenesedriver/GetElementText.java | 30 -- .../selenesedriver/GetElementValue.java | 30 -- .../selenesedriver/GetPageSource.java | 28 -- .../internal/selenesedriver/GetSize.java | 51 ---- .../internal/selenesedriver/GetTagName.java | 35 --- .../internal/selenesedriver/GetTitle.java | 27 -- .../internal/selenesedriver/GetUrl.java | 36 --- .../selenesedriver/IsElementDisplayed.java | 29 -- .../selenesedriver/IsElementEnabled.java | 34 --- .../selenesedriver/IsElementSelected.java | 41 --- .../internal/selenesedriver/NewSession.java | 55 ---- .../internal/selenesedriver/QuitSelenium.java | 28 -- .../selenesedriver/ScriptExecutor.java | 103 ------- .../selenesedriver/SeleneseFunction.java | 29 -- .../internal/selenesedriver/SendKeys.java | 79 ------ .../selenesedriver/SubmitElement.java | 62 ----- .../selenesedriver/SwitchToFrame.java | 70 ----- .../selenesedriver/TakeScreenshot.java | 28 -- .../internal/selenesedriver/build.desc | 13 - 34 files changed, 1 insertion(+), 1620 deletions(-) delete mode 100644 java/client/src/org/openqa/selenium/SeleneseCommandExecutor.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/AbstractElementFinder.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/ClearElement.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/ClickElement.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/Close.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/ElementFunction.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/ExecuteAsyncScript.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/ExecuteScript.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/FindElement.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/FindElements.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetActiveElement.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetCurrentUrl.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementAttribute.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementText.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementValue.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetPageSource.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetSize.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetTagName.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetTitle.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/GetUrl.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementDisplayed.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementEnabled.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementSelected.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/NewSession.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/QuitSelenium.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/ScriptExecutor.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/SeleneseFunction.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/SendKeys.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/SubmitElement.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/SwitchToFrame.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/TakeScreenshot.java delete mode 100644 java/client/src/org/openqa/selenium/internal/selenesedriver/build.desc diff --git a/Rakefile b/Rakefile index 1eb51d676d3aa..4f3e02e75b5f7 100644 --- a/Rakefile +++ b/Rakefile @@ -180,7 +180,7 @@ task :android_client => ['//java/client/src/org/openqa/selenium/android'] task :android_server => ['//android:android-server'] # TODO(simon): test-core should go first, but it's changing the least for now. -task :test_selenium => [ :'test-rc', :'test-v1-emulation', :'test-selenium-backed-webdriver', :'test-core'] +task :test_selenium => [ :'test-rc', :'test-v1-emulation', :'test-core'] task :'test-v1-emulation' => [ '//java/client/test/com/thoughtworks/selenium:firefox-emulation-test:run' ] task :'test-rc' => ['//java/client/test/org/openqa/selenium:RcBrowserLauncherTests:run', diff --git a/java/client/src/org/openqa/selenium/SeleneseCommandExecutor.java b/java/client/src/org/openqa/selenium/SeleneseCommandExecutor.java deleted file mode 100644 index b50faf8531d02..0000000000000 --- a/java/client/src/org/openqa/selenium/SeleneseCommandExecutor.java +++ /dev/null @@ -1,262 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium; - -import static org.openqa.selenium.remote.DriverCommand.CLEAR_ELEMENT; -import static org.openqa.selenium.remote.DriverCommand.CLICK_ELEMENT; -import static org.openqa.selenium.remote.DriverCommand.CLOSE; -import static org.openqa.selenium.remote.DriverCommand.EXECUTE_ASYNC_SCRIPT; -import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT; -import static org.openqa.selenium.remote.DriverCommand.FIND_CHILD_ELEMENT; -import static org.openqa.selenium.remote.DriverCommand.FIND_CHILD_ELEMENTS; -import static org.openqa.selenium.remote.DriverCommand.FIND_ELEMENT; -import static org.openqa.selenium.remote.DriverCommand.FIND_ELEMENTS; -import static org.openqa.selenium.remote.DriverCommand.GET; -import static org.openqa.selenium.remote.DriverCommand.GET_ACTIVE_ELEMENT; -import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_URL; -import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_ATTRIBUTE; -import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_SIZE; -import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_TAG_NAME; -import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_TEXT; -import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_VALUE; -import static org.openqa.selenium.remote.DriverCommand.GET_PAGE_SOURCE; -import static org.openqa.selenium.remote.DriverCommand.GET_TITLE; -import static org.openqa.selenium.remote.DriverCommand.IMPLICITLY_WAIT; -import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_DISPLAYED; -import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_ENABLED; -import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_SELECTED; -import static org.openqa.selenium.remote.DriverCommand.NEW_SESSION; -import static org.openqa.selenium.remote.DriverCommand.QUIT; -import static org.openqa.selenium.remote.DriverCommand.SCREENSHOT; -import static org.openqa.selenium.remote.DriverCommand.SEND_KEYS_TO_ELEMENT; -import static org.openqa.selenium.remote.DriverCommand.SET_SCRIPT_TIMEOUT; -import static org.openqa.selenium.remote.DriverCommand.SUBMIT_ELEMENT; -import static org.openqa.selenium.remote.DriverCommand.SWITCH_TO_FRAME; - -import com.google.common.collect.Maps; - -import com.thoughtworks.selenium.CommandProcessor; -import com.thoughtworks.selenium.DefaultSelenium; -import com.thoughtworks.selenium.HttpCommandProcessor; -import com.thoughtworks.selenium.Selenium; -import com.thoughtworks.selenium.SeleniumException; - -import org.openqa.selenium.internal.selenesedriver.ClearElement; -import org.openqa.selenium.internal.selenesedriver.ClickElement; -import org.openqa.selenium.internal.selenesedriver.Close; -import org.openqa.selenium.internal.selenesedriver.ExecuteAsyncScript; -import org.openqa.selenium.internal.selenesedriver.ExecuteScript; -import org.openqa.selenium.internal.selenesedriver.FindElement; -import org.openqa.selenium.internal.selenesedriver.FindElements; -import org.openqa.selenium.internal.selenesedriver.GetActiveElement; -import org.openqa.selenium.internal.selenesedriver.GetCurrentUrl; -import org.openqa.selenium.internal.selenesedriver.GetElementAttribute; -import org.openqa.selenium.internal.selenesedriver.GetElementText; -import org.openqa.selenium.internal.selenesedriver.GetElementValue; -import org.openqa.selenium.internal.selenesedriver.GetPageSource; -import org.openqa.selenium.internal.selenesedriver.GetSize; -import org.openqa.selenium.internal.selenesedriver.GetTagName; -import org.openqa.selenium.internal.selenesedriver.GetTitle; -import org.openqa.selenium.internal.selenesedriver.GetUrl; -import org.openqa.selenium.internal.selenesedriver.IsElementDisplayed; -import org.openqa.selenium.internal.selenesedriver.IsElementEnabled; -import org.openqa.selenium.internal.selenesedriver.IsElementSelected; -import org.openqa.selenium.internal.selenesedriver.NewSession; -import org.openqa.selenium.internal.selenesedriver.QuitSelenium; -import org.openqa.selenium.internal.selenesedriver.SeleneseFunction; -import org.openqa.selenium.internal.selenesedriver.SendKeys; -import org.openqa.selenium.internal.selenesedriver.SubmitElement; -import org.openqa.selenium.internal.selenesedriver.SwitchToFrame; -import org.openqa.selenium.internal.selenesedriver.TakeScreenshot; -import org.openqa.selenium.remote.BeanToJsonConverter; -import org.openqa.selenium.remote.BrowserType; -import org.openqa.selenium.remote.Command; -import org.openqa.selenium.remote.CommandExecutor; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.ErrorCodes; -import org.openqa.selenium.remote.JsonToBeanConverter; -import org.openqa.selenium.remote.Response; - -import java.io.File; -import java.net.URL; -import java.util.Map; - -/** - * @deprecated - */ -@Deprecated -public class SeleneseCommandExecutor implements CommandExecutor { - private final ErrorCodes errorCodes; - private final Selenium instance; - private Map> functions = Maps.newHashMap(); - - public SeleneseCommandExecutor(URL seleniumServer, URL remoteAddress, Capabilities capabilities) { - this(new HttpCommandProcessor( - seleniumServer.getHost(), seleniumServer.getPort(), - startCommand(capabilities), remoteAddress.toString())); - } - - public SeleneseCommandExecutor(CommandProcessor processor) { - this(new DefaultSelenium(processor)); - } - - public SeleneseCommandExecutor(Selenium instance) { - this.instance = instance; - errorCodes = new ErrorCodes(); - - prepareCommands(); - } - - public Selenium getWrappedSelenium() { - return instance; - } - - public Response execute(Command command) { - SeleneseFunction function = functions.get(command.getName()); - if (function == null) { - throw new UnsupportedOperationException("cannot execute: " + command.getName()); - } - - try { - Response response = new Response(); - response.setValue(function.apply(instance, command.getParameters())); - return response; - } catch (Exception e) { - return prepareExceptionResponse(e); - } - } - - private Response prepareExceptionResponse(Exception e) { - Response response = new Response(); - - Exception toUse = e; - if (e instanceof SeleniumException) { - // World of fragility. *sigh* - if (e.getMessage().matches("ERROR: (Threw an exception: )?Element .+ not found")) { - toUse = new StaleElementReferenceException(e.getMessage(), e); - } - } - response.setStatus(errorCodes.toStatusCode(toUse)); - response.setState(errorCodes.toState(response.getStatus())); - - // It's like a lesson in inefficiency - Object raw = - new JsonToBeanConverter().convert(Map.class, new BeanToJsonConverter().convert(toUse)); - response.setValue(raw); - return response; - } - - public void addCommand(String methodName, SeleneseFunction command) { - functions.put(methodName, command); - } - - private void prepareCommands() { - FindElement findElement = new FindElement(); - FindElements findElements = new FindElements(); - SeleneseTimeouts timeouts = new SeleneseTimeouts( - findElement.implicitlyWait(), findElements.implicitlyWait()); - ExecuteAsyncScript executeAsyncScript = new ExecuteAsyncScript(); - - addCommand(CLEAR_ELEMENT, new ClearElement()); - addCommand(CLICK_ELEMENT, new ClickElement()); - addCommand(CLOSE, new Close()); - addCommand(GET_CURRENT_URL, new GetCurrentUrl()); - addCommand(EXECUTE_SCRIPT, new ExecuteScript()); - addCommand(EXECUTE_ASYNC_SCRIPT, executeAsyncScript); - addCommand(SET_SCRIPT_TIMEOUT, executeAsyncScript.setScriptTimeout()); - addCommand(FIND_CHILD_ELEMENT, findElement); - addCommand(FIND_CHILD_ELEMENTS, findElements); - addCommand(FIND_ELEMENT, findElement); - addCommand(FIND_ELEMENTS, findElements); - addCommand(IMPLICITLY_WAIT, timeouts); - addCommand(GET, new GetUrl()); - addCommand(GET_ACTIVE_ELEMENT, new GetActiveElement()); - addCommand(GET_ELEMENT_ATTRIBUTE, new GetElementAttribute()); - addCommand(GET_ELEMENT_SIZE, new GetSize()); - addCommand(GET_ELEMENT_TEXT, new GetElementText()); - addCommand(GET_ELEMENT_VALUE, new GetElementValue()); - addCommand(GET_ELEMENT_TAG_NAME, new GetTagName()); - addCommand(GET_TITLE, new GetTitle()); - addCommand(IS_ELEMENT_DISPLAYED, new IsElementDisplayed()); - addCommand(IS_ELEMENT_ENABLED, new IsElementEnabled()); - addCommand(IS_ELEMENT_SELECTED, new IsElementSelected()); - addCommand(NEW_SESSION, new NewSession()); - addCommand(GET_PAGE_SOURCE, new GetPageSource()); - addCommand(SCREENSHOT, new TakeScreenshot()); - addCommand(SEND_KEYS_TO_ELEMENT, new SendKeys()); - addCommand(SWITCH_TO_FRAME, new SwitchToFrame()); - addCommand(SUBMIT_ELEMENT, new SubmitElement()); - addCommand(QUIT, new QuitSelenium()); - } - - private static String startCommand(Capabilities capabilities) { - String browser = capabilities.getBrowserName(); - - if (browser.startsWith("*")) { - return browser; - } - - if (BrowserType.FIREFOX.equals(browser)) { - return "*chrome"; - } - - if (BrowserType.SAFARI.equals(browser)) { - String path = findSafari(); - return "*safari " + path; - } - - if (BrowserType.CHROME.equals(browser)) { - return "*googlechrome /Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; - } - - throw new IllegalArgumentException( - "Cannot determine which selenium type to use: " + capabilities.getBrowserName()); - } - - private static String findSafari() { - if (Platform.getCurrent().is(Platform.WINDOWS)) { - File[] locations = new File[] { - new File("C:\\Program Files (x86)\\Safari\\safari.exe"), - new File("C:\\Program Files\\Safari\\safari.exe") - }; - - for (File location : locations) { - if (location.exists()) { - return location.getAbsolutePath(); - } - } - } - - return ""; - } - - private class SeleneseTimeouts implements SeleneseFunction { - private final SeleneseFunction[] functions; - - public SeleneseTimeouts(SeleneseFunction... functions) { - this.functions = functions; - } - - public Void apply(Selenium selenium, Map args) { - for (SeleneseFunction function : functions) { - function.apply(selenium, args); - } - - return null; - } - } -} diff --git a/java/client/src/org/openqa/selenium/build.desc b/java/client/src/org/openqa/selenium/build.desc index e207b424c7dd8..80746aec6c878 100644 --- a/java/client/src/org/openqa/selenium/build.desc +++ b/java/client/src/org/openqa/selenium/build.desc @@ -121,16 +121,6 @@ java_library(name = "webdriver-backed-selenium", "//java/client/src/org/openqa/selenium/internal/seleniumemulation:scripts", ]) -java_library(name = "selenium-backed-webdriver", - srcs = [ - "SeleneseCommandExecutor.java", - ], - deps = [ - "//java/client/src/org/openqa/selenium/internal/selenesedriver", - "//java/client/src/org/openqa/selenium/firefox", - "//java/client/src/org/openqa/selenium/remote", - ]) - java_library(name = "client-combined", deps = [ "//java/client/src/com/thoughtworks/selenium:selenium", diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/AbstractElementFinder.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/AbstractElementFinder.java deleted file mode 100644 index 706e1e9220292..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/AbstractElementFinder.java +++ /dev/null @@ -1,99 +0,0 @@ -/* -Copyright 2010 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - - -package org.openqa.selenium.internal.selenesedriver; - -import static org.openqa.selenium.net.Urls.urlEncode; - -import com.google.common.collect.ImmutableMap; - -import com.thoughtworks.selenium.Selenium; -import com.thoughtworks.selenium.SeleniumException; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.List; -import java.util.Map; - -public abstract class AbstractElementFinder implements SeleneseFunction { - private long implicitlyWait = 0; - - protected abstract T executeFind(Selenium selenium, String how, String using, String parentLocator); - - protected abstract T onFailure(String how, String using); - - protected Map newElement(String key) { - String locator = "stored=" + urlEncode(key); - return ImmutableMap.of("ELEMENT", locator); - } - - public T apply(Selenium selenium, Map args) { - String how = (String) args.get("using"); - String using = (String) args.get("value"); - String parentLocator = (String) args.get("id"); - - if (parentLocator == null) { - parentLocator = "selenium.browserbot.getDocument()"; - } else { - try { - parentLocator = - "selenium.browserbot.findElement('" + URLDecoder.decode(parentLocator, "UTF-8") + "')"; - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); // To change body of catch statement use File | Settings | File - // Templates. - } - } - - using = using.replaceAll("'", "\\\\'"); - - long startTime = System.currentTimeMillis(); - do { - try { - T result = executeFind(selenium, how, using, parentLocator); - - if (result instanceof List && ((List) result).size() == 0) { - continue; - } - - return result; - } catch (SeleniumException e) { - // Ignore. The element couldn't be found - } - sleepQuietly(200); - } while (System.currentTimeMillis() - startTime <= implicitlyWait); - - return onFailure(how, using); - } - - private static void sleepQuietly(long ms) { - try { - Thread.sleep(ms); - } catch (InterruptedException ignored) { - } - } - - public ImplicitWait implicitlyWait() { - return new ImplicitWait(); - } - - public class ImplicitWait implements SeleneseFunction { - public Object apply(Selenium selenium, Map args) { - AbstractElementFinder.this.implicitlyWait = ((Number) args.get("ms")).longValue(); - return null; - } - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/ClearElement.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/ClearElement.java deleted file mode 100644 index daf63c6bdbe71..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/ClearElement.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class ClearElement extends ElementFunction { - public Void apply(Selenium selenium, Map args) { - selenium.type(getLocator(args), ""); - return null; - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/ClickElement.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/ClickElement.java deleted file mode 100644 index 54e77eeea4bc2..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/ClickElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class ClickElement extends ElementFunction { - public Void apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - selenium.getEval("var e = selenium.browserbot.findElement('" + locator + - "'); webdriver.atoms.inputs.click(e)"); - return null; - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/Close.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/Close.java deleted file mode 100644 index 06c442c708ec4..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/Close.java +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2010 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; -import com.thoughtworks.selenium.SeleniumException; - -import java.util.Map; - -public class Close implements SeleneseFunction { - public Void apply(Selenium selenium, Map args) { - selenium.close(); - - // WebDriver quits the browser once all windows are closed. - String[] allWindowIds = selenium.getAllWindowIds(); - if (allWindowIds.length == 1) { - boolean open = true; - try { - // Hilariously, this script will detonate if the window has been closed - selenium.getEval("selenium.browserbot.getCurrentWindow().closed"); - } catch (SeleniumException e) { - open = false; - } - - if (!open) { - selenium.stop(); - } - } - - return null; - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/ElementFunction.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/ElementFunction.java deleted file mode 100644 index 2e50e7163ff75..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/ElementFunction.java +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import org.openqa.selenium.WebDriverException; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Map; - -public abstract class ElementFunction implements SeleneseFunction { - public String getLocator(Map parameters) { - String locator = (String) parameters.get("id"); - - try { - return URLDecoder.decode(locator, "utf-8"); - } catch (UnsupportedEncodingException e) { - // Should never happen - throw new WebDriverException(e); - } - } - - protected String escape(String toEscape) { - return toEscape.replaceAll("'", "\\\\'"); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/ExecuteAsyncScript.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/ExecuteAsyncScript.java deleted file mode 100644 index bad0e9e24968b..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/ExecuteAsyncScript.java +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2007-2010 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.List; -import java.util.Map; - -public class ExecuteAsyncScript implements SeleneseFunction { - - private long timeoutMillis = 0; - - public Object apply(Selenium selenium, Map parameters) { - String script = (String) parameters.get("script"); - - @SuppressWarnings({"unchecked"}) - List args = (List) parameters.get("args"); - - return new ScriptExecutor(selenium) - .executeAsyncScript(script, args, timeoutMillis); - } - - public SeleneseFunction setScriptTimeout() { - return new SeleneseFunction() { - - public Object apply(Selenium selenium, Map args) { - ExecuteAsyncScript.this.timeoutMillis = ((Number) args.get("ms")).longValue(); - return null; - } - }; - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/ExecuteScript.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/ExecuteScript.java deleted file mode 100644 index 9096de46632bc..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/ExecuteScript.java +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.List; -import java.util.Map; - -public class ExecuteScript implements SeleneseFunction { - - public Object apply(Selenium selenium, Map parameters) { - String script = (String) parameters.get("script"); - - @SuppressWarnings({"unchecked"}) - List args = (List) parameters.get("args"); - - return new ScriptExecutor(selenium) - .inContextOfApplicationUnderTest() - .executeScript(script, args); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/FindElement.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/FindElement.java deleted file mode 100644 index 1563bbb1a8fe4..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/FindElement.java +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import org.openqa.selenium.NoSuchElementException; - -import java.util.Map; - -public class FindElement extends AbstractElementFinder> { - - private final static String SCRIPT = - "var by = {}; by['%s'] = '%s'; " + - "var e = bot.locators.findElement(by, %s);" + - "e = core.firefox.unwrap(e); " + - "bot.inject.cache.addElement(e);"; - - @Override - protected Map executeFind(Selenium selenium, String how, String using, - String parentLocator) { - String locator = String.format(SCRIPT, how, using, parentLocator); - - String key = selenium.getEval(locator); - return newElement(key); - } - - @Override - protected Map onFailure(String how, String using) { - throw new NoSuchElementException( - String.format("No elements were found: %s=%s ", how, using)); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/FindElements.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/FindElements.java deleted file mode 100644 index ff9bab09a105d..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/FindElements.java +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright 2010 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.google.common.base.Splitter; -import com.google.common.collect.Lists; - -import com.thoughtworks.selenium.Selenium; - -import java.util.List; -import java.util.Map; - -public class FindElements extends AbstractElementFinder>> { - - private static final String SCRIPT = - "selenium.browserbot.findElementsLikeWebDriver('%s', '%s', %s);"; - - @Override - protected List> executeFind(Selenium selenium, String how, String using, - String parentLocator) { - String result = - selenium.getEval(String.format(SCRIPT, how, using, parentLocator)); - - Iterable allKeys = Splitter.on(",").split(result); - List> toReturn = Lists.newArrayList(); - - for (String key : allKeys) { - if (key.length() > 0) { - toReturn.add(newElement(key)); - } - } - - return toReturn; - } - - @Override - protected List> onFailure(String how, String using) { - return Lists.newArrayList(); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetActiveElement.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetActiveElement.java deleted file mode 100644 index 177e2ff7c1a82..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetActiveElement.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -Copyright 2011 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import static org.openqa.selenium.net.Urls.urlEncode; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableMap; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class GetActiveElement implements SeleneseFunction> { - - private static final String SCRIPT = Joiner.on('\n').join( - "(function() {", - " var doc = selenium.browserbot.getDocument();", - " var el = doc.activeElement || doc.body;", - " el = core.firefox.unwrap(el);", - " return bot.inject.cache.addElement(el);", - "})()"); - - public Map apply(Selenium selenium, Map args) { - String key = selenium.getEval(SCRIPT); - String locator = "stored=" + urlEncode(key); - return ImmutableMap.of("ELEMENT", locator); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetCurrentUrl.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetCurrentUrl.java deleted file mode 100644 index 93e4b5b685c1d..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetCurrentUrl.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class GetCurrentUrl implements SeleneseFunction { - - public String apply(Selenium selenium, Map args) { - return selenium.getLocation(); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementAttribute.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementAttribute.java deleted file mode 100644 index fea2eaafba9c0..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementAttribute.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class GetElementAttribute extends ElementFunction { - - public String apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - String name = (String) args.get("name"); - - String script = String.format( - "var e = selenium.browserbot.findElement('%s');" + - "webdriver.atoms.element.getAttribute(e, '%s');", - locator, escape(name)); - - String result = selenium.getEval(script); - - return "null".equals(result) ? null : result; - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementText.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementText.java deleted file mode 100644 index ca83aa94650a9..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementText.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class GetElementText extends ElementFunction { - - public String apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - return selenium.getText(locator); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementValue.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementValue.java deleted file mode 100644 index dd49b65173bfc..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetElementValue.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class GetElementValue extends ElementFunction { - - public String apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - return selenium.getValue(locator); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetPageSource.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetPageSource.java deleted file mode 100644 index 0a21cc4c798d6..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetPageSource.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class GetPageSource implements SeleneseFunction { - - public String apply(Selenium selenium, Map args) { - return selenium.getHtmlSource(); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetSize.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetSize.java deleted file mode 100644 index d624a4bc98a3e..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetSize.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -Copyright 2011 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import static com.google.common.base.Joiner.on; - -import com.google.common.collect.ImmutableMap; - -import com.thoughtworks.selenium.Selenium; - -import org.openqa.selenium.WebDriverException; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Map; - -public class GetSize extends ElementFunction> { - - public Map apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - String value = selenium.getEval(on("\n").join( - "(function() {", - " var element = selenium.browserbot.findElement('LOCATOR');", - " var size = goog.style.getSize(element);", - " return '{\"width\":' + size.width + ',\"height\":' + size.height + '}';", - "})();").replace("LOCATOR", locator)); - - try { - JSONObject json = new JSONObject(value); - return ImmutableMap.of("width", json.getInt("width"), "height", json.getInt("height")); - } catch (JSONException e) { - throw new WebDriverException(e); - } - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetTagName.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetTagName.java deleted file mode 100644 index 4fea48262d2fa..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetTagName.java +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class GetTagName extends ElementFunction { - public String apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - String value = selenium.getEval(getTagNameJs.replace("LOCATOR", locator)); - return value == null ? null : value.toLowerCase(); - } - - private static String getTagNameJs = - "(function tagName() {" - + " return selenium.browserbot.findElement('LOCATOR').tagName;" - + "})();"; -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetTitle.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetTitle.java deleted file mode 100644 index 93537c830f0db..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetTitle.java +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class GetTitle implements SeleneseFunction { - public String apply(Selenium selenium, Map args) { - return selenium.getTitle(); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetUrl.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/GetUrl.java deleted file mode 100644 index 4cb4769c7c948..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/GetUrl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; -import com.thoughtworks.selenium.SeleniumException; - -import java.util.Map; - -public class GetUrl implements SeleneseFunction { - public Void apply(Selenium selenium, Map args) { - selenium.open((String) args.get("url"), "true"); - - // WebDriver blocks until the page is loaded. - try { - selenium.waitForPageToLoad("30"); - } catch (SeleniumException e) { - // Well, we say webdriver blocks, it doesn't always. - } - return null; - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementDisplayed.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementDisplayed.java deleted file mode 100644 index 476121d0688e3..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementDisplayed.java +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class IsElementDisplayed extends ElementFunction { - public Boolean apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - return selenium.isVisible(locator); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementEnabled.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementEnabled.java deleted file mode 100644 index 5a530a404269d..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementEnabled.java +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; -import com.thoughtworks.selenium.SeleniumException; - -import java.util.Map; - -public class IsElementEnabled extends ElementFunction { - public Boolean apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - try { - return selenium.isEditable(locator); - } catch (SeleniumException e) { - return false; - } - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementSelected.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementSelected.java deleted file mode 100644 index b5ef59706e704..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/IsElementSelected.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class IsElementSelected extends ElementFunction { - - public Boolean apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - // What are we dealing with? - String value = selenium.getEval(selectedJs.replace("LOCATOR", locator)); - - return Boolean.valueOf(value); - } - - private final String selectedJs = - "(function isSelected() { " - + " var e = selenium.browserbot.findElement('LOCATOR'); " - + " if ('OPTION' == e.tagName) return e.selected ? 'true' : 'false'; " - + " if (e.type == 'checkbox' || e.type == 'radio') return !!e.checked ? 'true' : 'false'; " - + " return 'false'" - + "})()"; -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/NewSession.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/NewSession.java deleted file mode 100644 index f7e3824efd283..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/NewSession.java +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.BrowserConfigurationOptions; -import com.thoughtworks.selenium.Selenium; - -import org.openqa.selenium.Capabilities; -import org.openqa.selenium.Platform; -import org.openqa.selenium.remote.CapabilityType; - -import java.util.HashMap; -import java.util.Map; - -public class NewSession implements SeleneseFunction> { - public Map apply(Selenium selenium, Map args) { - Capabilities capabilities = (Capabilities) args.get("desiredCapabilities"); - - selenium.start(getBrowserConfigurationOptions(capabilities)); - - // Emulate behaviour of webdriver - selenium.useXpathLibrary("native"); - selenium.allowNativeXpath("true"); - - Map seenCapabilities = new HashMap(); - seenCapabilities.put(CapabilityType.BROWSER_NAME, capabilities.getBrowserName()); - seenCapabilities.put(CapabilityType.VERSION, capabilities.getVersion()); - seenCapabilities.put(CapabilityType.PLATFORM, Platform.getCurrent().toString()); - seenCapabilities.put(CapabilityType.SUPPORTS_JAVASCRIPT, true); - seenCapabilities.put(CapabilityType.TAKES_SCREENSHOT, true); - return seenCapabilities; - } - - private String getBrowserConfigurationOptions(Capabilities capabilities) { - BrowserConfigurationOptions options = new BrowserConfigurationOptions(); - for (Map.Entry capability : capabilities.asMap().entrySet()) { - options.set(capability.getKey(), String.valueOf(capability.getValue())); - } - return options.serialize(); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/QuitSelenium.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/QuitSelenium.java deleted file mode 100644 index 2c96e1c0cb6d6..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/QuitSelenium.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class QuitSelenium implements SeleneseFunction { - public Void apply(Selenium selenium, Map args) { - selenium.stop(); - return null; - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/ScriptExecutor.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/ScriptExecutor.java deleted file mode 100644 index bc66fd51007af..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/ScriptExecutor.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - Copyright 2011 Software Freedom Conservancy. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import static java.util.concurrent.TimeUnit.MILLISECONDS; - -import com.google.common.base.Stopwatch; -import com.google.common.collect.Lists; - -import com.thoughtworks.selenium.Selenium; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.openqa.selenium.remote.ErrorHandler; -import org.openqa.selenium.remote.JsonException; -import org.openqa.selenium.remote.JsonToBeanConverter; -import org.openqa.selenium.remote.Response; - -import java.io.StringWriter; -import java.util.List; - -class ScriptExecutor { - - private final Selenium selenium; - - private boolean inAppUnderTest = false; - - public ScriptExecutor(Selenium selenium) { - this.selenium = selenium; - } - - public ScriptExecutor inContextOfApplicationUnderTest() { - this.inAppUnderTest = true; - return this; - } - - public Object executeScript(String script, Object... args) { - return executeScript(script, Lists.newArrayList(args)); - } - - public T executeScript(String script, List args) { - - StringWriter sw = new StringWriter(); - try { - new JSONWriter(sw) - .object() - .key("script").value(script) - .key("args").value(args) - .endObject(); - } catch (JSONException e) { - throw new JsonException(e); - } - - String evalScript = String.format("core.inject.executeScript(%s, %s);", - sw, inAppUnderTest ? "selenium.browserbot.getCurrentWindow()" : "null"); - return evaluateScript(evalScript); - } - - public T executeAsyncScript(String script, List args, long timeoutMillis) { - StringWriter sw = new StringWriter(); - try { - new JSONWriter(sw) - .object() - .key("script").value(script) - .key("args").value(args) - .key("timeout").value(timeoutMillis) - .endObject(); - } catch (JSONException e) { - throw new JsonException(e); - } - - String evalScript = String.format("core.inject.executeAsyncScript(%s);", sw); - return evaluateScript(evalScript); - } - - @SuppressWarnings({"unchecked"}) - private T evaluateScript(String script) { - Stopwatch stopWatch = new Stopwatch(); - stopWatch.start(); - String result = selenium.getEval(script); - stopWatch.stop(); - - Response response = new JsonToBeanConverter() - .convert(Response.class, result); - new ErrorHandler() - .throwIfResponseFailed(response, stopWatch.elapsed(MILLISECONDS)); - return (T) response.getValue(); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/SeleneseFunction.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/SeleneseFunction.java deleted file mode 100644 index 0a2acb1f6a605..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/SeleneseFunction.java +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -/** - * @deprecated - */ -@Deprecated -public interface SeleneseFunction { - T apply(Selenium selenium, Map args); -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/SendKeys.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/SendKeys.java deleted file mode 100644 index 5ad3d6ac49aa2..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/SendKeys.java +++ /dev/null @@ -1,79 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; -import com.thoughtworks.selenium.SeleniumException; - -import java.io.File; -import java.util.Map; - -public class SendKeys extends ElementFunction { - public Void apply(Selenium selenium, Map args) { - String locator = getLocator(args); - - CharSequence[] allKeys = (CharSequence[]) args.get("value"); - - StringBuilder builder = new StringBuilder(); - for (CharSequence seq : allKeys) { - builder.append(seq); - } - - if (isFileInput(selenium, locator)) { - String toType = builder.toString(); - if (isLocalFile(toType)) { - toType = convertToFileUrl(toType); - } - - selenium.attachFile(locator, toType); - } else { - String script = String.format( - "(function() { " - + "var e = selenium.browserbot.findElement('%s');" - // Do a check to see if we're in an extension - + "if (bot.userAgent.FIREFOX_EXTENSION && Components && Components['classes'] && XPCNativeWrapper) {" - + " e = core.firefox.unwrap(e);" - + "}" - + "bot.action.type(e, '%s');})();", - locator, builder.toString().replaceAll("'", "\\'") - ); - selenium.getEval(script); - } - - return null; - } - - private String convertToFileUrl(String toType) { - return new File(toType).toURI().toString(); - } - - private boolean isFileInput(Selenium selenium, String locator) { - try { - String type = selenium.getAttribute(locator + "@type"); - return "file".equals(type.toLowerCase()); - } catch (SeleniumException e) { - // Thrown if the "type" attribute is omitted. By definition, this means - // that the element is not a file input element - return false; - } - } - - private boolean isLocalFile(String name) { - File file = new File(name); - return file.exists() && file.canRead(); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/SubmitElement.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/SubmitElement.java deleted file mode 100644 index 38899ad8f3c30..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/SubmitElement.java +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import org.openqa.selenium.WebDriverException; - -import java.util.Map; - -public class SubmitElement extends ElementFunction { - - public Void apply(Selenium selenium, Map args) { - String locator = getLocator(args).replace("'", "\\'"); - - String eval = submitJs.replace("LOCATOR", locator); - - String result = selenium.getEval(eval); - - if (!"true".equals(result)) { - throw new WebDriverException(result); - } - - // Turns out that on Firefox, the load may not have started. Rest for a very - // short time to let it being. - sleep(100); - - return null; - } - - private void sleep(long timeout) { - try { - Thread.sleep(timeout); - } catch (InterruptedException e) { - throw new WebDriverException(e); - } - } - - private final String submitJs = - "(function submit() { " - + "var curr = selenium.browserbot.findElement('LOCATOR'); " - + "while (curr != null && curr.tagName != 'FORM') {" - + " curr = curr.parentNode || curr.parentElement; " - + "} " - + "if (curr) { curr.submit(); return 'true'; } " - + "return 'false'; " - + "})()"; -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/SwitchToFrame.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/SwitchToFrame.java deleted file mode 100644 index 376d8ab9911c0..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/SwitchToFrame.java +++ /dev/null @@ -1,70 +0,0 @@ -/* -Copyright 2007-2009 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; -import com.thoughtworks.selenium.SeleniumException; - -import org.openqa.selenium.NoSuchFrameException; -import org.openqa.selenium.WebDriverException; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Map; - -public class SwitchToFrame implements SeleneseFunction { - public Void apply(Selenium selenium, Map args) { - Object id = args.get("id"); - - if (id == null) { - selenium.selectFrame("relative=top"); - return null; - } - - try { - if (id instanceof Number) { - selenium.selectFrame("index=" + ((Number) id).longValue()); - } else if (id instanceof String) { - selenium.selectFrame((String) id); - } else if (id instanceof Map) { - @SuppressWarnings({"unchecked"}) - String locator = getLocator((Map) id); - selenium.selectFrame(locator); - } else { - throw new IllegalArgumentException("Illegal frame switch target: (" + - id.getClass().getName() + ") " + id); - } - } catch (SeleniumException e) { - throw new NoSuchFrameException(e.getMessage(), e); - } - - return null; - } - - private String getLocator(Map elementMap) { - if (elementMap.containsKey("ELEMENT")) { - try { - return URLDecoder.decode((String) elementMap.get("ELEMENT"), "utf-8"); - } catch (UnsupportedEncodingException e) { - // Should never happen. - throw new WebDriverException(e); - } - } - // Should never happen - throw new IllegalArgumentException("Map does not define a WebElement"); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/TakeScreenshot.java b/java/client/src/org/openqa/selenium/internal/selenesedriver/TakeScreenshot.java deleted file mode 100644 index 82b72bb0ae7e7..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/TakeScreenshot.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2011 Selenium committers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ - -package org.openqa.selenium.internal.selenesedriver; - -import com.thoughtworks.selenium.Selenium; - -import java.util.Map; - -public class TakeScreenshot implements SeleneseFunction { - - public String apply(Selenium selenium, Map args) { - return selenium.captureEntirePageScreenshotToString(""); - } -} diff --git a/java/client/src/org/openqa/selenium/internal/selenesedriver/build.desc b/java/client/src/org/openqa/selenium/internal/selenesedriver/build.desc deleted file mode 100644 index 376157aee7d53..0000000000000 --- a/java/client/src/org/openqa/selenium/internal/selenesedriver/build.desc +++ /dev/null @@ -1,13 +0,0 @@ - -java_library(name = "selenesedriver", - srcs = [ - "*.java", - ], - deps = [ - "//java/client/src/com/thoughtworks/selenium", - "//java/client/src/org/openqa/selenium:webdriver-api", - "//java/client/src/org/openqa/selenium/remote:base", - "//java/client/src/org/openqa/selenium/remote:common", - "//third_party/java/guava-libraries", - "//third_party/java/json", - ])