diff --git a/gradle.properties b/gradle.properties index 9bd535700..d2d4a6a43 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,4 @@ signing.secretKeyRingFile=PathToYourKeyRingFile ossrhUsername=your-jira-id ossrhPassword=your-jira-password -selenium.version=3.141.59 +selenium.version=4.0.0 diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index fd512197a..1e880c569 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -68,8 +68,7 @@ */ @SuppressWarnings("unchecked") public class AppiumDriver - extends DefaultGenericMobileDriver implements ComparesImages, FindsByImage, FindsByCustom, - ExecutesDriverScript, LogsEvents, HasSettings { + extends DefaultGenericMobileDriver implements ComparesImages, ExecutesDriverScript, LogsEvents, HasSettings { private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true); // frequently used command parameters @@ -134,23 +133,6 @@ public AppiumDriver(Capabilities desiredCapabilities) { this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities); } - /** - * Changes platform name and returns new capabilities. - * - * @param originalCapabilities the given {@link Capabilities}. - * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has - * to be set up - * @return {@link Capabilities} with changed mobile platform value - * @deprecated Please use {@link #updateDefaultPlatformName(Capabilities, String)} instead - */ - @Deprecated - protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities, - String newPlatform) { - DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities); - dc.setCapability(PLATFORM_NAME, newPlatform); - return dc; - } - /** * Changes platform name if it is not set and returns new capabilities. * @@ -174,49 +156,6 @@ public List findElements(By by) { return super.findElements(by); } - @Override - public List findElements(String by, String using) { - return super.findElements(by, using); - } - - @Override - public List findElementsById(String id) { - return super.findElementsById(id); - } - - public List findElementsByLinkText(String using) { - return super.findElementsByLinkText(using); - } - - public List findElementsByPartialLinkText(String using) { - return super.findElementsByPartialLinkText(using); - } - - public List findElementsByTagName(String using) { - return super.findElementsByTagName(using); - } - - public List findElementsByName(String using) { - return super.findElementsByName(using); - } - - public List findElementsByClassName(String using) { - return super.findElementsByClassName(using); - } - - public List findElementsByCssSelector(String using) { - return super.findElementsByCssSelector(using); - } - - public List findElementsByXPath(String using) { - return super.findElementsByXPath(using); - } - - @Override - public List findElementsByAccessibilityId(String using) { - return super.findElementsByAccessibilityId(using); - } - @Override public ExecuteMethod getExecuteMethod() { return executeMethod; diff --git a/src/main/java/io/appium/java_client/DefaultGenericMobileDriver.java b/src/main/java/io/appium/java_client/DefaultGenericMobileDriver.java index 0ca7a1dcc..e6d45f5f8 100644 --- a/src/main/java/io/appium/java_client/DefaultGenericMobileDriver.java +++ b/src/main/java/io/appium/java_client/DefaultGenericMobileDriver.java @@ -20,7 +20,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.Capabilities; -import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.CommandExecutor; import org.openqa.selenium.remote.RemoteWebDriver; @@ -49,112 +48,10 @@ public DefaultGenericMobileDriver(CommandExecutor executor, Capabilities desired return super.findElements(by); } - @Override public List findElements(String by, String using) { - return super.findElements(by, using); - } - @Override public T findElement(By by) { return (T) super.findElement(by); } - @Override public T findElement(String by, String using) { - return (T) super.findElement(by, using); - } - - @Override public List findElementsById(String id) { - return super.findElementsById(id); - } - - @Override public T findElementById(String id) { - return (T) super.findElementById(id); - } - - /** - * Finds a single element by link text. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public T findElementByLinkText(String using) throws WebDriverException { - return (T) super.findElementByLinkText(using); - } - - /** - * Finds many elements by link text. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public List findElementsByLinkText(String using) throws WebDriverException { - return super.findElementsByLinkText(using); - } - - /** - * Finds a single element by partial link text. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public T findElementByPartialLinkText(String using) throws WebDriverException { - return (T) super.findElementByPartialLinkText(using); - } - - /** - * Finds many elements by partial link text. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public List findElementsByPartialLinkText(String using) throws WebDriverException { - return super.findElementsByPartialLinkText(using); - } - - public T findElementByTagName(String using) { - return (T) super.findElementByTagName(using); - } - - public List findElementsByTagName(String using) { - return super.findElementsByTagName(using); - } - - public T findElementByName(String using) { - return (T) super.findElementByName(using); - } - - public List findElementsByName(String using) { - return super.findElementsByName(using); - } - - public T findElementByClassName(String using) { - return (T) super.findElementByClassName(using); - } - - public List findElementsByClassName(String using) { - return super.findElementsByClassName(using); - } - - /** - * Finds a single element by CSS selector. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public T findElementByCssSelector(String using) throws WebDriverException { - return (T) super.findElementByCssSelector(using); - } - - /** - * Finds many elements by CSS selector. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public List findElementsByCssSelector(String using) throws WebDriverException { - return super.findElementsByCssSelector(using); - } - - public T findElementByXPath(String using) { - return (T) super.findElementByXPath(using); - } - - public List findElementsByXPath(String using) { - return super.findElementsByXPath(using); - } - @Override public String toString() { Capabilities capabilities = getCapabilities(); diff --git a/src/main/java/io/appium/java_client/DefaultGenericMobileElement.java b/src/main/java/io/appium/java_client/DefaultGenericMobileElement.java index 2d8154880..6e1bfc64a 100644 --- a/src/main/java/io/appium/java_client/DefaultGenericMobileElement.java +++ b/src/main/java/io/appium/java_client/DefaultGenericMobileElement.java @@ -21,13 +21,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; -import org.openqa.selenium.internal.FindsByClassName; -import org.openqa.selenium.internal.FindsByCssSelector; -import org.openqa.selenium.internal.FindsById; -import org.openqa.selenium.internal.FindsByLinkText; -import org.openqa.selenium.internal.FindsByName; -import org.openqa.selenium.internal.FindsByTagName; -import org.openqa.selenium.internal.FindsByXPath; import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.remote.Response; @@ -35,11 +28,7 @@ import java.util.Map; @SuppressWarnings({"unchecked", "rawtypes"}) -abstract class DefaultGenericMobileElement extends RemoteWebElement - implements FindsByClassName, - FindsByCssSelector, FindsById, - FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath, FindsByFluentSelector, FindsByAccessibilityId, - ExecutesMethod { +abstract class DefaultGenericMobileElement extends RemoteWebElement implements ExecutesMethod { @Override public Response execute(String driverCommand, Map parameters) { return super.execute(driverCommand, parameters); @@ -53,127 +42,8 @@ abstract class DefaultGenericMobileElement extends RemoteW return super.findElements(by); } - @Override public List findElements(String by, String using) { - return super.findElements(by, using); - } - @Override public T findElement(By by) { return (T) super.findElement(by); } - @Override public T findElement(String by, String using) { - return (T) super.findElement(by, using); - } - - @Override public List findElementsById(String id) { - return super.findElementsById(id); - } - - @Override public T findElementById(String id) { - return (T) super.findElementById(id); - } - - /** - * Finds a single element by link text. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public T findElementByLinkText(String using) throws WebDriverException { - return (T) super.findElementByLinkText(using); - } - - /** - * Finds many elements by link text. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public List findElementsByLinkText(String using) throws WebDriverException { - return super.findElementsByLinkText(using); - } - - /** - * Finds a single element by partial link text. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public T findElementByPartialLinkText(String using) throws WebDriverException { - return (T) super.findElementByPartialLinkText(using); - } - - /** - * Finds many elements by partial link text. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public List findElementsByPartialLinkText(String using) throws WebDriverException { - return super.findElementsByPartialLinkText(using); - } - - public T findElementByTagName(String using) { - return (T) super.findElementByTagName(using); - } - - public List findElementsByTagName(String using) { - return super.findElementsByTagName(using); - } - - public T findElementByName(String using) { - return (T) super.findElementByName(using); - } - - public List findElementsByName(String using) { - return super.findElementsByName(using); - } - - public T findElementByClassName(String using) { - return (T) super.findElementByClassName(using); - } - - public List findElementsByClassName(String using) { - return super.findElementsByClassName(using); - } - - /** - * Finds a single element by CSS selector. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public T findElementByCssSelector(String using) throws WebDriverException { - return (T) super.findElementByCssSelector(using); - } - - /** - * Finds many elements by CSS selector. - * - * @throws WebDriverException This method doesn't work against native app UI. - */ - public List findElementsByCssSelector(String using) throws WebDriverException { - return super.findElementsByCssSelector(using); - } - - public T findElementByXPath(String using) { - return (T) super.findElementByXPath(using); - } - - public List findElementsByXPath(String using) { - return super.findElementsByXPath(using); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException because it may not work against native app UI. - */ - public void submit() throws WebDriverException { - super.submit(); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException because it may not work against native app UI. - */ - public String getCssValue(String propertyName) throws WebDriverException { - return super.getCssValue(propertyName); - } } diff --git a/src/main/java/io/appium/java_client/DriverMobileCommand.java b/src/main/java/io/appium/java_client/DriverMobileCommand.java deleted file mode 100644 index 9d991d3cb..000000000 --- a/src/main/java/io/appium/java_client/DriverMobileCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -/** - * An empty interface defining constants for the standard commands defined in the Mobile JSON - * wire protocol. - * - * @author jonahss@gmail.com (Jonah Stiennon) - */ -public interface DriverMobileCommand { - //TODO Jonah: we'll probably need this -} diff --git a/src/main/java/io/appium/java_client/FindsByAccessibilityId.java b/src/main/java/io/appium/java_client/FindsByAccessibilityId.java deleted file mode 100644 index 4d79a33a4..000000000 --- a/src/main/java/io/appium/java_client/FindsByAccessibilityId.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebDriverException; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByAccessibilityId extends FindsByFluentSelector { - /** - * Method performs the searching for a single element by accessibility ID selector - * and value of the given selector. - * - * @param using an accessibility ID selector - * @return The first element that matches the given selector - * - * @throws WebDriverException This method is not applicable with browser/webview UI. - * @throws NoSuchElementException when no one element is found - */ - default T findElementByAccessibilityId(String using) { - return findElement(MobileSelector.ACCESSIBILITY.toString(), using); - } - - /** - * Method performs the searching for a list of elements by accessibility ID selector - * and value of the given selector. - * - * @param using an accessibility ID selector - * @return a list of elements that match the given selector - * - * @throws WebDriverException This method is not applicable with browser/webview UI. - */ - default List findElementsByAccessibilityId(String using) { - return findElements(MobileSelector.ACCESSIBILITY.toString(), using); - } -} diff --git a/src/main/java/io/appium/java_client/FindsByAndroidDataMatcher.java b/src/main/java/io/appium/java_client/FindsByAndroidDataMatcher.java deleted file mode 100644 index a60477870..000000000 --- a/src/main/java/io/appium/java_client/FindsByAndroidDataMatcher.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByAndroidDataMatcher extends FindsByFluentSelector { - - default T findElementByAndroidDataMatcher(String using) { - return findElement(MobileSelector.ANDROID_DATA_MATCHER.toString(), using); - } - - default List findElementsByAndroidDataMatcher(String using) { - return findElements(MobileSelector.ANDROID_DATA_MATCHER.toString(), using); - } -} diff --git a/src/main/java/io/appium/java_client/FindsByAndroidUIAutomator.java b/src/main/java/io/appium/java_client/FindsByAndroidUIAutomator.java deleted file mode 100644 index 50c7bafba..000000000 --- a/src/main/java/io/appium/java_client/FindsByAndroidUIAutomator.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebDriverException; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByAndroidUIAutomator extends FindsByFluentSelector { - - /** - * Method performs the searching for a single element by Android UIAutomator selector - * and value of the given selector. - * - * @param using an Android UIAutomator selector - * @return The first element that matches the given selector - * - * @throws WebDriverException This method is not applicable with browser/webview UI. - * @throws NoSuchElementException when no one element is found - */ - default T findElementByAndroidUIAutomator(String using) { - return findElement(MobileSelector.ANDROID_UI_AUTOMATOR.toString(), using); - } - - /** - * Method performs the searching for a list of elements by Android UIAutomator selector - * and value of the given selector. - * - * @param using an Android UIAutomator selector - * @return a list of elements that match the given selector - * - * @throws WebDriverException This method is not applicable with browser/webview UI. - */ - default List findElementsByAndroidUIAutomator(String using) { - return findElements(MobileSelector.ANDROID_UI_AUTOMATOR.toString(), using); - } -} diff --git a/src/main/java/io/appium/java_client/FindsByAndroidViewMatcher.java b/src/main/java/io/appium/java_client/FindsByAndroidViewMatcher.java deleted file mode 100644 index 1370cf3ae..000000000 --- a/src/main/java/io/appium/java_client/FindsByAndroidViewMatcher.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByAndroidViewMatcher extends FindsByFluentSelector { - - default T findElementByAndroidViewMatcher(String using) { - return findElement(MobileSelector.ANDROID_VIEW_MATCHER.toString(), using); - } - - default List findElementsByAndroidViewMatcher(String using) { - return findElements(MobileSelector.ANDROID_VIEW_MATCHER.toString(), using); - } -} diff --git a/src/main/java/io/appium/java_client/FindsByAndroidViewTag.java b/src/main/java/io/appium/java_client/FindsByAndroidViewTag.java deleted file mode 100644 index b1db5c432..000000000 --- a/src/main/java/io/appium/java_client/FindsByAndroidViewTag.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebDriverException; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByAndroidViewTag extends FindsByFluentSelector { - /** - * Method performs the searching for a single element by view tag selector - * and value of the given selector. - * - * @param using an view tag selector - * @return The first element that matches the given selector - * - * @throws WebDriverException This method is not applicable with browser/webview UI. - * @throws NoSuchElementException when no one element is found - */ - default T findElementByAndroidViewTag(String using) { - return findElement(MobileSelector.ANDROID_VIEWTAG.toString(), using); - } - - /** - * Method performs the searching for a list of elements by view tag selector - * and value of the given selector. - * - * @param using an view tag selector - * @return a list of elements that match the given selector - * - * @throws WebDriverException This method is not applicable with browser/webview UI. - */ - default List findElementsByAndroidViewTag(String using) { - return findElements(MobileSelector.ANDROID_VIEWTAG.toString(), using); - } -} diff --git a/src/main/java/io/appium/java_client/FindsByCustom.java b/src/main/java/io/appium/java_client/FindsByCustom.java deleted file mode 100644 index f908fc424..000000000 --- a/src/main/java/io/appium/java_client/FindsByCustom.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByCustom extends FindsByFluentSelector { - /** - * Performs the lookup for a single element by sending a selector to a custom element finding - * plugin. This type of locator requires the use of the 'customFindModules' capability and a - * separately-installed element finding plugin. - * - * @param selector selector to pass to the custom element finding plugin - * @return The first element that matches the given selector - * @see - * The documentation on custom element finding plugins and their use - * @throws NoSuchElementException when no element is found - * @since Appium 1.9.2 - */ - default T findElementByCustom(String selector) { - return findElement(MobileSelector.CUSTOM.toString(), selector); - } - - /** - * Performs the lookup for a single element by sending a selector to a custom element finding - * plugin. This type of locator requires the use of the 'customFindModules' capability and a - * separately-installed element finding plugin. - * - * @param selector selector to pass to the custom element finding plugin - * @return a list of elements that match the given selector or an empty list - * @see - * The documentation on custom element finding plugins and their use - * @since Appium 1.9.2 - */ - default List findElementsByCustom(String selector) { - return findElements(MobileSelector.CUSTOM.toString(), selector); - } -} \ No newline at end of file diff --git a/src/main/java/io/appium/java_client/FindsByFluentSelector.java b/src/main/java/io/appium/java_client/FindsByFluentSelector.java deleted file mode 100644 index f545f47be..000000000 --- a/src/main/java/io/appium/java_client/FindsByFluentSelector.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByFluentSelector { - - /** - * Method performs the searching for a single element by some selector defined by string - * and value of the given selector. - * - * @param by is a string selector - * @param using is a value of the given selector - * @return the first found element - * - * @throws org.openqa.selenium.WebDriverException when current session doesn't - * support the given selector or when value of the selector is not consistent. - * @throws org.openqa.selenium.NoSuchElementException when no one element is found - */ - T findElement(String by, String using); - - /** - * Method performs the searching for a list of elements by some selector defined by string - * and value of the given selector. - * - * @param by is a string selector - * @param using is a value of the given selector - * @return a list of elements - * - * @throws org.openqa.selenium.WebDriverException when current session doesn't support - * the given selector or when value of the selector is not consistent. - */ - List findElements(String by, String using); -} diff --git a/src/main/java/io/appium/java_client/FindsByImage.java b/src/main/java/io/appium/java_client/FindsByImage.java deleted file mode 100644 index 76de64fd1..000000000 --- a/src/main/java/io/appium/java_client/FindsByImage.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByImage extends FindsByFluentSelector { - /** - * Performs the lookup for a single element by matching its image template - * to the current full screen shot. This type of locator requires OpenCV libraries - * and bindings for NodeJS to be installed on the server machine. Lookup options - * fine-tuning might be done via {@link HasSettings#setSetting(Setting, Object)}. - * - * @param b64Template base64-encoded template image string. Supported image formats are the same - * as for OpenCV library. - * @return The first element that matches the given selector - * @throws NoSuchElementException when no element is found - * @see - * The documentation on Image Comparison Features - * @see - * The settings available for lookup fine-tuning - * @since Appium 1.8.2 - */ - default T findElementByImage(String b64Template) { - return findElement(MobileSelector.IMAGE.toString(), b64Template); - } - - /** - * Performs the lookup for a list of elements by matching them to image template - * in the current full screen shot. This type of locator requires OpenCV libraries - * and bindings for NodeJS to be installed on the server machine. Lookup options - * fine-tuning might be done via {@link HasSettings#setSetting(Setting, Object)}. - * - * @param b64Template base64-encoded template image string. Supported image formats are the same - * as for OpenCV library. - * @return a list of elements that match the given selector or an empty list - * @see - * The documentation on Image Comparison Features - * @see - * The settings available for lookup fine-tuning - * @since Appium 1.8.2 - */ - default List findElementsByImage(String b64Template) { - return findElements(MobileSelector.IMAGE.toString(), b64Template); - } -} diff --git a/src/main/java/io/appium/java_client/FindsByIosClassChain.java b/src/main/java/io/appium/java_client/FindsByIosClassChain.java deleted file mode 100644 index 92482663a..000000000 --- a/src/main/java/io/appium/java_client/FindsByIosClassChain.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByIosClassChain extends FindsByFluentSelector { - - default T findElementByIosClassChain(String using) { - return findElement(MobileSelector.IOS_CLASS_CHAIN.toString(), using); - } - - default List findElementsByIosClassChain(String using) { - return findElements(MobileSelector.IOS_CLASS_CHAIN.toString(), using); - } -} diff --git a/src/main/java/io/appium/java_client/FindsByIosNSPredicate.java b/src/main/java/io/appium/java_client/FindsByIosNSPredicate.java deleted file mode 100644 index 84bc3ff67..000000000 --- a/src/main/java/io/appium/java_client/FindsByIosNSPredicate.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByIosNSPredicate extends FindsByFluentSelector { - - default T findElementByIosNsPredicate(String using) { - return findElement(MobileSelector.IOS_PREDICATE_STRING.toString(), using); - } - - default List findElementsByIosNsPredicate(String using) { - return findElements(MobileSelector.IOS_PREDICATE_STRING.toString(), using); - } -} diff --git a/src/main/java/io/appium/java_client/FindsByWindowsAutomation.java b/src/main/java/io/appium/java_client/FindsByWindowsAutomation.java deleted file mode 100644 index 4416eb63f..000000000 --- a/src/main/java/io/appium/java_client/FindsByWindowsAutomation.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebDriverException; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByWindowsAutomation extends FindsByFluentSelector { - - /** - * Finds the first of elements that match the Windows UIAutomation selector supplied. - * - * @param selector a Windows UIAutomation selector - * @return The first element that matches the given selector - * @throws WebDriverException This method is not applicable with browser/webview UI. - * @throws NoSuchElementException when no one element is found - */ - default T findElementByWindowsUIAutomation(String selector) { - return findElement(MobileSelector.WINDOWS_UI_AUTOMATION.toString(), selector); - } - - /** - * Finds a list of elements that match the Windows UIAutomation selector supplied. - * - * @param selector a Windows UIAutomation selector - * @return a list of elements that match the given selector - * @throws WebDriverException This method is not applicable with browser/webview UI. - */ - default List findElementsByWindowsUIAutomation(String selector) { - return findElements(MobileSelector.WINDOWS_UI_AUTOMATION.toString(), selector); - } -} diff --git a/src/main/java/io/appium/java_client/IllegalCoordinatesException.java b/src/main/java/io/appium/java_client/IllegalCoordinatesException.java deleted file mode 100644 index 8167ad65d..000000000 --- a/src/main/java/io/appium/java_client/IllegalCoordinatesException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -import org.openqa.selenium.WebDriverException; - -public class IllegalCoordinatesException extends WebDriverException { - private static final long serialVersionUID = 1L; - - public IllegalCoordinatesException(String message) { - super(message); - } - -} diff --git a/src/main/java/io/appium/java_client/MobileBy.java b/src/main/java/io/appium/java_client/MobileBy.java index b8fd3d5db..183656627 100644 --- a/src/main/java/io/appium/java_client/MobileBy.java +++ b/src/main/java/io/appium/java_client/MobileBy.java @@ -20,45 +20,39 @@ import lombok.Getter; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.By; +import org.openqa.selenium.By.Remotable; import org.openqa.selenium.SearchContext; -import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import java.io.Serializable; import java.util.List; @SuppressWarnings("serial") -public abstract class MobileBy extends By { - - private static final String ERROR_TEXT = "The class %s of the given context " - + "doesn't implement %s nor %s. Sorry. It is impossible to find something."; +public abstract class MobileBy extends By implements Remotable { @Getter(AccessLevel.PROTECTED) private final String locatorString; - private final MobileSelector selector; - - private static IllegalArgumentException formIllegalArgumentException(Class givenClass, - Class class1, Class class2) { - return new IllegalArgumentException(String.format(ERROR_TEXT, givenClass.getCanonicalName(), - class1.getCanonicalName(), class2.getCanonicalName())); - } + private final Parameters parameters; - protected MobileBy(MobileSelector selector, String locatorString) { + protected MobileBy(String selector, String locatorString) { if (StringUtils.isBlank(locatorString)) { throw new IllegalArgumentException("Must supply a not empty locator value."); } this.locatorString = locatorString; - this.selector = selector; + this.parameters = new Parameters(selector, locatorString); } @SuppressWarnings("unchecked") @Override public List findElements(SearchContext context) { - return (List) ((FindsByFluentSelector) context) - .findElements(selector.toString(), getLocatorString()); + return context.findElements(this); } @Override public WebElement findElement(SearchContext context) { - return ((FindsByFluentSelector) context) - .findElement(selector.toString(), getLocatorString()); + return context.findElement(this); + } + + @Override + public Parameters getRemoteParameters() { + return parameters; } /** @@ -168,64 +162,20 @@ public static By custom(final String selector) { return new ByCustom(selector); } + /** + * For IOS it is the full name of the XCUI element and begins with XCUIElementType. + * For Android it is the full name of the UIAutomator2 class (e.g.: android.widget.TextView) + * @param selector the class name of the element + * @return an instance of {@link ByClassName} + */ + public static By className(final String selector) { + return new ByClassName(selector); + } public static class ByAndroidUIAutomator extends MobileBy implements Serializable { - public ByAndroidUIAutomator(String uiautomatorText) { - super(MobileSelector.ANDROID_UI_AUTOMATOR, uiautomatorText); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override - public List findElements(SearchContext context) throws WebDriverException, - IllegalArgumentException { - Class contextClass = context.getClass(); - - if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) { - return FindsByAndroidUIAutomator.class.cast(context) - .findElementsByAndroidUIAutomator(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class, - FindsByFluentSelector.class); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) throws WebDriverException, - IllegalArgumentException { - Class contextClass = context.getClass(); - - if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) { - return FindsByAndroidUIAutomator.class.cast(context) - .findElementByAndroidUIAutomator(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class, - FindsByFluentSelector.class); + super("-android uiautomator", uiautomatorText); } @Override public String toString() { @@ -237,59 +187,7 @@ public List findElements(SearchContext context) throws WebDriverExce public static class ByAccessibilityId extends MobileBy implements Serializable { public ByAccessibilityId(String accessibilityId) { - super(MobileSelector.ACCESSIBILITY, accessibilityId); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override - public List findElements(SearchContext context) throws WebDriverException, - IllegalArgumentException { - Class contextClass = context.getClass(); - - if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) { - return FindsByAccessibilityId.class.cast(context) - .findElementsByAccessibilityId(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class, - FindsByFluentSelector.class); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) throws WebDriverException, - IllegalArgumentException { - Class contextClass = context.getClass(); - - if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) { - return FindsByAccessibilityId.class.cast(context) - .findElementByAccessibilityId(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class, - FindsByFluentSelector.class); + super("accessibility id", accessibilityId); } @Override public String toString() { @@ -300,56 +198,7 @@ public List findElements(SearchContext context) throws WebDriverExce public static class ByIosClassChain extends MobileBy implements Serializable { protected ByIosClassChain(String locatorString) { - super(MobileSelector.IOS_CLASS_CHAIN, locatorString); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override public List findElements(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) { - return FindsByIosClassChain.class.cast(context) - .findElementsByIosClassChain(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class, - FindsByFluentSelector.class); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) { - return FindsByIosClassChain.class.cast(context) - .findElementByIosClassChain(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class, - FindsByFluentSelector.class); + super("-ios class chain", locatorString); } @Override public String toString() { @@ -360,176 +209,29 @@ protected ByIosClassChain(String locatorString) { public static class ByAndroidDataMatcher extends MobileBy implements Serializable { protected ByAndroidDataMatcher(String locatorString) { - super(MobileSelector.ANDROID_DATA_MATCHER, locatorString); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override public List findElements(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByAndroidDataMatcher.class.isAssignableFrom(contextClass)) { - return FindsByAndroidDataMatcher.class.cast(context) - .findElementsByAndroidDataMatcher(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAndroidDataMatcher.class, - FindsByFluentSelector.class); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByAndroidDataMatcher.class.isAssignableFrom(contextClass)) { - return FindsByAndroidDataMatcher.class.cast(context) - .findElementByAndroidDataMatcher(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAndroidDataMatcher.class, - FindsByFluentSelector.class); + super("-android datamatcher", locatorString); } @Override public String toString() { - return "By.FindsByAndroidDataMatcher: " + getLocatorString(); + return "By.AndroidDataMatcher: " + getLocatorString(); } } public static class ByAndroidViewMatcher extends MobileBy implements Serializable { protected ByAndroidViewMatcher(String locatorString) { - super(MobileSelector.ANDROID_VIEW_MATCHER, locatorString); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override public List findElements(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByAndroidViewMatcher.class.isAssignableFrom(contextClass)) { - return FindsByAndroidViewMatcher.class.cast(context) - .findElementsByAndroidViewMatcher(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAndroidViewMatcher.class, - FindsByFluentSelector.class); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByAndroidViewMatcher.class.isAssignableFrom(contextClass)) { - return FindsByAndroidViewMatcher.class.cast(context) - .findElementByAndroidViewMatcher(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAndroidViewMatcher.class, - FindsByFluentSelector.class); + super("-android viewmatcher", locatorString); } @Override public String toString() { - return "By.FindsByAndroidViewMatcher: " + getLocatorString(); + return "By.AndroidViewMatcher: " + getLocatorString(); } } public static class ByIosNsPredicate extends MobileBy implements Serializable { protected ByIosNsPredicate(String locatorString) { - super(MobileSelector.IOS_PREDICATE_STRING, locatorString); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override public List findElements(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) { - return FindsByIosNSPredicate.class.cast(context) - .findElementsByIosNsPredicate(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class, - FindsByFluentSelector.class); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) { - return FindsByIosNSPredicate.class.cast(context) - .findElementByIosNsPredicate(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class, - FindsByFluentSelector.class); + super("-ios predicate string", locatorString); } @Override public String toString() { @@ -540,108 +242,15 @@ protected ByIosNsPredicate(String locatorString) { public static class ByWindowsAutomation extends MobileBy implements Serializable { protected ByWindowsAutomation(String locatorString) { - super(MobileSelector.WINDOWS_UI_AUTOMATION, locatorString); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override public List findElements(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) { - return FindsByWindowsAutomation.class.cast(context) - .findElementsByWindowsUIAutomation(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByWindowsAutomation.class, - FindsByFluentSelector.class); + super("-windows uiautomation", locatorString); } - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) { - return FindsByWindowsAutomation.class.cast(context) - .findElementByWindowsUIAutomation(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class, - FindsByWindowsAutomation.class); - } } public static class ByImage extends MobileBy implements Serializable { protected ByImage(String b64Template) { - super(MobileSelector.IMAGE, b64Template); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override public List findElements(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByImage.class.isAssignableFrom(contextClass)) { - return FindsByImage.class.cast(context).findElementsByImage(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByImage.class, FindsByFluentSelector.class); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByImage.class.isAssignableFrom(contextClass)) { - return FindsByImage.class.cast(context).findElementByImage(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByImage.class, FindsByFluentSelector.class); + super("-image", b64Template); } @Override public String toString() { @@ -652,52 +261,7 @@ protected ByImage(String b64Template) { public static class ByCustom extends MobileBy implements Serializable { protected ByCustom(String selector) { - super(MobileSelector.CUSTOM, selector); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override public List findElements(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByCustom.class.isAssignableFrom(contextClass)) { - return FindsByCustom.class.cast(context).findElementsByCustom(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByCustom.class, FindsByFluentSelector.class); - } - - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) { - Class contextClass = context.getClass(); - - if (FindsByCustom.class.isAssignableFrom(contextClass)) { - return FindsByCustom.class.cast(context).findElementByCustom(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByCustom.class, FindsByFluentSelector.class); + super("-custom", selector); } @Override public String toString() { @@ -708,63 +272,22 @@ protected ByCustom(String selector) { public static class ByAndroidViewTag extends MobileBy implements Serializable { public ByAndroidViewTag(String tag) { - super(MobileSelector.ANDROID_VIEWTAG, tag); + super("-android viewtag", tag); } - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @SuppressWarnings("unchecked") - @Override - public List findElements(SearchContext context) throws WebDriverException, - IllegalArgumentException { - Class contextClass = context.getClass(); - - if (FindsByAndroidViewTag.class.isAssignableFrom(contextClass)) { - return FindsByAndroidViewTag.class.cast(context) - .findElementsByAndroidViewTag(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElements(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAndroidViewTag.class, - FindsByFluentSelector.class); + @Override public String toString() { + return "By.AndroidViewTag: " + getLocatorString(); } + } + + public static class ByClassName extends MobileBy implements Serializable { - /** - * {@inheritDoc} - * - * @throws WebDriverException when current session doesn't support the given selector or when - * value of the selector is not consistent. - * @throws IllegalArgumentException when it is impossible to find something on the given - * {@link SearchContext} instance - */ - @Override public WebElement findElement(SearchContext context) throws WebDriverException, - IllegalArgumentException { - Class contextClass = context.getClass(); - - if (FindsByAndroidViewTag.class.isAssignableFrom(contextClass)) { - return FindsByAndroidViewTag.class.cast(context) - .findElementByAndroidViewTag(getLocatorString()); - } - - if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) { - return super.findElement(context); - } - - throw formIllegalArgumentException(contextClass, FindsByAndroidViewTag.class, - FindsByFluentSelector.class); + protected ByClassName(String selector) { + super("class name", selector); } @Override public String toString() { - return "By.AndroidViewTag: " + getLocatorString(); + return "By.className: " + getLocatorString(); } } } diff --git a/src/main/java/io/appium/java_client/MobileDriver.java b/src/main/java/io/appium/java_client/MobileDriver.java index e982d5419..708f3b8f0 100644 --- a/src/main/java/io/appium/java_client/MobileDriver.java +++ b/src/main/java/io/appium/java_client/MobileDriver.java @@ -22,55 +22,14 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.html5.LocationContext; -import org.openqa.selenium.internal.FindsByClassName; -import org.openqa.selenium.internal.FindsByCssSelector; -import org.openqa.selenium.internal.FindsById; -import org.openqa.selenium.internal.FindsByLinkText; -import org.openqa.selenium.internal.FindsByName; -import org.openqa.selenium.internal.FindsByTagName; -import org.openqa.selenium.internal.FindsByXPath; import java.util.List; public interface MobileDriver extends WebDriver, PerformsTouchActions, ContextAware, Rotatable, - FindsByAccessibilityId, LocationContext, HidesKeyboard, HasDeviceTime, - InteractsWithFiles, InteractsWithApps, HasAppStrings, FindsByClassName, FindsByCssSelector, FindsById, - FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath, FindsByFluentSelector, ExecutesMethod, + LocationContext, HidesKeyboard, HasDeviceTime, InteractsWithFiles, InteractsWithApps, HasAppStrings, ExecutesMethod, HasSessionDetails { List findElements(By by); T findElement(By by); - - T findElementByClassName(String className); - - List findElementsByClassName(String className); - - T findElementByCssSelector(String cssSelector); - - List findElementsByCssSelector(String cssSelector); - - T findElementById(String id); - - List findElementsById(String id); - - T findElementByLinkText(String linkText); - - List findElementsByLinkText(String linkText); - - T findElementByPartialLinkText(String partialLinkText); - - List findElementsByPartialLinkText(String partialLinkText); - - T findElementByName(String name); - - List findElementsByName(String name); - - T findElementByTagName(String tagName); - - List findElementsByTagName(String tagName); - - T findElementByXPath(String xPath); - - List findElementsByXPath(String xPath); } diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index a8decf61d..45c932b12 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -29,8 +29,6 @@ public abstract class MobileElement extends DefaultGenericMobileElement { - protected FileDetector fileDetector; - /** * Method returns central coordinates of an element. * @return The instance of the {@link org.openqa.selenium.Point} @@ -46,46 +44,6 @@ public Point getCenter() { return super.findElements(by); } - @Override public List findElements(String by, String using) { - return super.findElements(by, using); - } - - @Override public List findElementsById(String id) { - return super.findElementsById(id); - } - - public List findElementsByLinkText(String using) { - return super.findElementsByLinkText(using); - } - - public List findElementsByPartialLinkText(String using) { - return super.findElementsByPartialLinkText(using); - } - - public List findElementsByTagName(String using) { - return super.findElementsByTagName(using); - } - - public List findElementsByName(String using) { - return super.findElementsByName(using); - } - - public List findElementsByClassName(String using) { - return super.findElementsByClassName(using); - } - - public List findElementsByCssSelector(String using) { - return super.findElementsByCssSelector(using); - } - - public List findElementsByXPath(String using) { - return super.findElementsByXPath(using); - } - - @Override public List findElementsByAccessibilityId(String using) { - return super.findElementsByAccessibilityId(using); - } - /** * This method sets the new value of the attribute "value". * diff --git a/src/main/java/io/appium/java_client/MobileSelector.java b/src/main/java/io/appium/java_client/MobileSelector.java deleted file mode 100644 index 0fbe3284e..000000000 --- a/src/main/java/io/appium/java_client/MobileSelector.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client; - -public enum MobileSelector { - ACCESSIBILITY("accessibility id"), - ANDROID_UI_AUTOMATOR("-android uiautomator"), - IOS_UI_AUTOMATION("-ios uiautomation"), - IOS_PREDICATE_STRING("-ios predicate string"), - IOS_CLASS_CHAIN("-ios class chain"), - WINDOWS_UI_AUTOMATION("-windows uiautomation"), - IMAGE("-image"), - ANDROID_VIEWTAG("-android viewtag"), - ANDROID_DATA_MATCHER("-android datamatcher"), - ANDROID_VIEW_MATCHER("-android viewmatcher"), - CUSTOM("-custom"); - - private final String selector; - - MobileSelector(String selector) { - this.selector = selector; - } - - @Override public String toString() { - return selector; - } -} diff --git a/src/main/java/io/appium/java_client/android/Activity.java b/src/main/java/io/appium/java_client/android/Activity.java index da957d746..41a17dc8c 100644 --- a/src/main/java/io/appium/java_client/android/Activity.java +++ b/src/main/java/io/appium/java_client/android/Activity.java @@ -2,7 +2,6 @@ import lombok.Data; import lombok.experimental.Accessors; -import okhttp3.Interceptor; import static com.google.common.base.Preconditions.checkArgument; import static org.apache.commons.lang3.StringUtils.isBlank; diff --git a/src/main/java/io/appium/java_client/android/AndroidDriver.java b/src/main/java/io/appium/java_client/android/AndroidDriver.java index 1994bb69a..be4bd8e3d 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -26,10 +26,6 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecuteCDPCommand; -import io.appium.java_client.FindsByAndroidDataMatcher; -import io.appium.java_client.FindsByAndroidViewMatcher; -import io.appium.java_client.FindsByAndroidUIAutomator; -import io.appium.java_client.FindsByAndroidViewTag; import io.appium.java_client.HasOnScreenKeyboard; import io.appium.java_client.LocksDevice; import io.appium.java_client.android.connection.HasNetworkConnection; @@ -63,13 +59,10 @@ */ public class AndroidDriver extends AppiumDriver - implements PressesKey, HasNetworkConnection, PushesFiles, StartsActivity, - FindsByAndroidUIAutomator, FindsByAndroidViewTag, FindsByAndroidDataMatcher, - FindsByAndroidViewMatcher, LocksDevice, HasAndroidSettings, HasAndroidDeviceDetails, - HasSupportedPerformanceDataType, AuthenticatesByFinger, HasOnScreenKeyboard, - CanRecordScreen, SupportsSpecialEmulatorCommands, - SupportsNetworkStateManagement, ListensToLogcatMessages, HasAndroidClipboard, - HasBattery, ExecuteCDPCommand, SupportsExtendedGeolocationCommands { + implements PressesKey, HasNetworkConnection, PushesFiles, StartsActivity,LocksDevice, HasAndroidSettings, + HasAndroidDeviceDetails, HasSupportedPerformanceDataType, AuthenticatesByFinger, HasOnScreenKeyboard, + CanRecordScreen, SupportsSpecialEmulatorCommands, SupportsNetworkStateManagement, ListensToLogcatMessages, + HasAndroidClipboard, HasBattery, ExecuteCDPCommand, SupportsExtendedGeolocationCommands { private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID; diff --git a/src/main/java/io/appium/java_client/android/AndroidElement.java b/src/main/java/io/appium/java_client/android/AndroidElement.java index 95899e4db..5c1231c24 100644 --- a/src/main/java/io/appium/java_client/android/AndroidElement.java +++ b/src/main/java/io/appium/java_client/android/AndroidElement.java @@ -19,15 +19,9 @@ import static io.appium.java_client.android.AndroidMobileCommandHelper.replaceElementValueCommand; import io.appium.java_client.CommandExecutionHelper; -import io.appium.java_client.FindsByAndroidDataMatcher; -import io.appium.java_client.FindsByAndroidViewMatcher; -import io.appium.java_client.FindsByAndroidUIAutomator; -import io.appium.java_client.FindsByAndroidViewTag; import io.appium.java_client.MobileElement; -public class AndroidElement extends MobileElement - implements FindsByAndroidUIAutomator, FindsByAndroidDataMatcher, - FindsByAndroidViewMatcher, FindsByAndroidViewTag { +public class AndroidElement extends MobileElement { /** * This method replace current text value. * @param value a new value diff --git a/src/main/java/io/appium/java_client/android/AndroidOptions.java b/src/main/java/io/appium/java_client/android/AndroidOptions.java index 768bf75eb..780f92cd4 100644 --- a/src/main/java/io/appium/java_client/android/AndroidOptions.java +++ b/src/main/java/io/appium/java_client/android/AndroidOptions.java @@ -22,11 +22,15 @@ public class AndroidOptions extends MobileOptions { public AndroidOptions() { - setPlatformName(MobilePlatform.ANDROID); + setAndroidPlatformName(); } public AndroidOptions(Capabilities source) { - this(); - merge(source); + super(source); + setAndroidPlatformName(); + } + + private void setAndroidPlatformName() { + setPlatformName(MobilePlatform.ANDROID); } } diff --git a/src/main/java/io/appium/java_client/events/DefaultAspect.java b/src/main/java/io/appium/java_client/events/DefaultAspect.java index 345ec77ee..3ce9794be 100644 --- a/src/main/java/io/appium/java_client/events/DefaultAspect.java +++ b/src/main/java/io/appium/java_client/events/DefaultAspect.java @@ -97,19 +97,6 @@ class DefaultAspect { + "execution(* org.openqa.selenium.WebDriver.TargetLocator.*(..)) || " + "execution(* org.openqa.selenium.JavascriptExecutor.*(..)) || " + "execution(* org.openqa.selenium.ContextAware.*(..)) || " - + "execution(* io.appium.java_client.FindsByAccessibilityId.*(..)) || " - + "execution(* io.appium.java_client.FindsByAndroidUIAutomator.*(..)) || " - + "execution(* io.appium.java_client.FindsByAndroidDataMatcher.*(..)) || " - + "execution(* io.appium.java_client.FindsByAndroidViewMatcher.*(..)) || " - + "execution(* io.appium.java_client.FindsByWindowsAutomation.*(..)) || " - + "execution(* io.appium.java_client.FindsByIosNSPredicate.*(..)) || " - + "execution(* org.openqa.selenium.internal.FindsByClassName.*(..)) || " - + "execution(* org.openqa.selenium.internal.FindsByCssSelector.*(..)) || " - + "execution(* org.openqa.selenium.internal.FindsById.*(..)) || " - + "execution(* org.openqa.selenium.internal.FindsByLinkText.*(..)) || " - + "execution(* org.openqa.selenium.internal.FindsByName.*(..)) || " - + "execution(* org.openqa.selenium.internal.FindsByTagName.*(..)) || " - + "execution(* org.openqa.selenium.internal.FindsByXPath.*(..)) || " + "execution(* org.openqa.selenium.WebDriver.Window.*(..)) || " + "execution(* io.appium.java_client.android.AndroidElement.*(..)) || " + "execution(* io.appium.java_client.ios.IOSElement.*(..)) || " diff --git a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java index 9f8674a90..d69e39312 100644 --- a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java +++ b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java @@ -22,9 +22,9 @@ import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.remote.CapabilityType; +import org.openqa.selenium.remote.JsonToWebElementConverter; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.RemoteWebElement; -import org.openqa.selenium.remote.internal.JsonToWebElementConverter; import java.lang.reflect.Constructor; diff --git a/src/main/java/io/appium/java_client/ios/IOSDriver.java b/src/main/java/io/appium/java_client/ios/IOSDriver.java index 229aac70b..ffd4a8a0c 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -22,8 +22,6 @@ import com.google.common.collect.ImmutableMap; import io.appium.java_client.AppiumDriver; -import io.appium.java_client.FindsByIosClassChain; -import io.appium.java_client.FindsByIosNSPredicate; import io.appium.java_client.HasOnScreenKeyboard; import io.appium.java_client.HidesKeyboardWithKeyName; import io.appium.java_client.LocksDevice; @@ -59,9 +57,8 @@ */ public class IOSDriver extends AppiumDriver - implements HidesKeyboardWithKeyName, ShakesDevice, HasIOSSettings, HasOnScreenKeyboard, - LocksDevice, PerformsTouchID, FindsByIosNSPredicate, FindsByIosClassChain, - PushesFiles, CanRecordScreen, HasIOSClipboard, ListensToSyslogMessages, + implements HidesKeyboardWithKeyName, ShakesDevice, HasIOSSettings, HasOnScreenKeyboard, LocksDevice, + PerformsTouchID, PushesFiles, CanRecordScreen, HasIOSClipboard, ListensToSyslogMessages, HasBattery { private static final String IOS_DEFAULT_PLATFORM = MobilePlatform.IOS; diff --git a/src/main/java/io/appium/java_client/ios/IOSElement.java b/src/main/java/io/appium/java_client/ios/IOSElement.java index a406053a0..55aa47110 100644 --- a/src/main/java/io/appium/java_client/ios/IOSElement.java +++ b/src/main/java/io/appium/java_client/ios/IOSElement.java @@ -16,10 +16,7 @@ package io.appium.java_client.ios; -import io.appium.java_client.FindsByIosClassChain; -import io.appium.java_client.FindsByIosNSPredicate; import io.appium.java_client.MobileElement; -public class IOSElement extends MobileElement - implements FindsByIosNSPredicate, FindsByIosClassChain { +public class IOSElement extends MobileElement { } diff --git a/src/main/java/io/appium/java_client/ios/IOSOptions.java b/src/main/java/io/appium/java_client/ios/IOSOptions.java index 14af6aad6..9d4c82b6e 100644 --- a/src/main/java/io/appium/java_client/ios/IOSOptions.java +++ b/src/main/java/io/appium/java_client/ios/IOSOptions.java @@ -22,11 +22,15 @@ public class IOSOptions extends MobileOptions { public IOSOptions() { - setPlatformName(MobilePlatform.IOS); + setIOSPlatformName(); } public IOSOptions(Capabilities source) { - this(); - merge(source); + super(source); + setIOSPlatformName(); + } + + private void setIOSPlatformName() { + setPlatformName(MobilePlatform.IOS); } } diff --git a/src/main/java/io/appium/java_client/mac/FindsByClassChain.java b/src/main/java/io/appium/java_client/mac/FindsByClassChain.java deleted file mode 100644 index 3d4eaffcc..000000000 --- a/src/main/java/io/appium/java_client/mac/FindsByClassChain.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client.mac; - -import io.appium.java_client.FindsByFluentSelector; -import io.appium.java_client.MobileSelector; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByClassChain extends FindsByFluentSelector { - - /** - * Perform single element lookup by class chain expression. - * Read https://github.com/appium/appium-mac2-driver#element-location - * for more details on elements location strategies supported by Mac2 driver. - * - * @param using A valid class chain lookup expression. - * @return The found element - */ - default T findElementByClassChain(String using) { - return findElement(MobileSelector.IOS_CLASS_CHAIN.toString(), using); - } - - /** - * Perform multiple elements lookup by class chain search expression. - * Read https://github.com/appium/appium-mac2-driver#element-location - * for more details on elements location strategies supported by Mac2 driver. - * - * @param using A valid class chain lookup expression. - * @return The array of found elements or an empty one if no matches have been found. - */ - default List findElementsByClassChain(String using) { - return findElements(MobileSelector.IOS_CLASS_CHAIN.toString(), using); - } -} diff --git a/src/main/java/io/appium/java_client/mac/FindsByNsPredicate.java b/src/main/java/io/appium/java_client/mac/FindsByNsPredicate.java deleted file mode 100644 index 665732eb3..000000000 --- a/src/main/java/io/appium/java_client/mac/FindsByNsPredicate.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client.mac; - -import io.appium.java_client.FindsByFluentSelector; -import io.appium.java_client.MobileSelector; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByNsPredicate extends FindsByFluentSelector { - - /** - * Perform single element lookup by predicate search expression. - * Read https://github.com/appium/appium-mac2-driver#element-location - * for more details on elements location strategies supported by Mac2 driver. - * - * @param using A valid predicate lookup expression. - * @return The found element - */ - default T findElementByNsPredicate(String using) { - return findElement(MobileSelector.IOS_PREDICATE_STRING.toString(), using); - } - - /** - * Perform multiple elements lookup by predicate search expression. - * Read https://github.com/appium/appium-mac2-driver#element-location - * for more details on elements location strategies supported by Mac2 driver. - * - * @param using A valid predicate lookup expression. - * @return The array of found elements or an empty one if no matches have been found. - */ - default List findElementsByNsPredicate(String using) { - return findElements(MobileSelector.IOS_PREDICATE_STRING.toString(), using); - } -} diff --git a/src/main/java/io/appium/java_client/mac/Mac2Driver.java b/src/main/java/io/appium/java_client/mac/Mac2Driver.java index d76eaf5d7..215c28971 100644 --- a/src/main/java/io/appium/java_client/mac/Mac2Driver.java +++ b/src/main/java/io/appium/java_client/mac/Mac2Driver.java @@ -44,9 +44,7 @@ * * @since Appium 1.20.0 */ -public class Mac2Driver - extends AppiumDriver implements CanRecordScreen, FindsByClassChain, - FindsByNsPredicate, HasSettings { +public class Mac2Driver extends AppiumDriver implements CanRecordScreen, HasSettings { public Mac2Driver(HttpCommandExecutor executor, Capabilities capabilities) { super(executor, prepareCaps(capabilities)); } diff --git a/src/main/java/io/appium/java_client/mac/Mac2Element.java b/src/main/java/io/appium/java_client/mac/Mac2Element.java index 905bada6e..e41042e8d 100644 --- a/src/main/java/io/appium/java_client/mac/Mac2Element.java +++ b/src/main/java/io/appium/java_client/mac/Mac2Element.java @@ -18,6 +18,5 @@ import io.appium.java_client.MobileElement; -public class Mac2Element extends MobileElement implements - FindsByClassChain, FindsByNsPredicate { +public class Mac2Element extends MobileElement { } diff --git a/src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java b/src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java index 718cd403c..4b853f046 100644 --- a/src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java +++ b/src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java @@ -46,7 +46,7 @@ enum Strategies { }, BYCLASSNAME("className") { @Override By getBy(Annotation annotation) { - return By.className(getValue(annotation, this)); + return MobileBy.className(getValue(annotation, this)); } }, BYID("id") { diff --git a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java index 2b0f77f7e..28af10cfc 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -44,16 +44,21 @@ import org.openqa.selenium.remote.ProtocolHandshake; import org.openqa.selenium.remote.Response; import org.openqa.selenium.remote.ResponseCodec; +import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; +import org.openqa.selenium.remote.http.Filter; import org.openqa.selenium.remote.http.HttpClient; +import org.openqa.selenium.remote.http.HttpHandler; import org.openqa.selenium.remote.http.HttpRequest; import org.openqa.selenium.remote.http.HttpResponse; -import org.openqa.selenium.remote.http.W3CHttpCommandCodec; +import org.openqa.selenium.remote.http.WebSocket; +import org.openqa.selenium.remote.http.WebSocket.Listener; import org.openqa.selenium.remote.service.DriverService; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; +import java.io.UncheckedIOException; import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -156,13 +161,6 @@ protected HttpClient getClient() { return getPrivateFieldValue("client", HttpClient.class); } - protected HttpClient withRequestsPatchedByIdempotencyKey(HttpClient httpClient) { - return (request) -> { - request.setHeader(IDEMPOTENCY_KEY_HEADER, UUID.randomUUID().toString().toLowerCase()); - return httpClient.execute(request); - }; - } - private Response createSession(Command command) throws IOException { if (getCommandCodec() != null) { throw new SessionNotCreatedException("Session already exists"); @@ -191,7 +189,10 @@ public Result createSession(HttpClient client, Command command) throws IOExcepti createSessionMethod.setAccessible(true); Optional result = (Optional) createSessionMethod.invoke(this, - withRequestsPatchedByIdempotencyKey(client), contentStream, counter.getCount()); + client.with(httpHandler -> req -> { + req.setHeader(IDEMPOTENCY_KEY_HEADER, UUID.randomUUID().toString().toLowerCase()); + return httpHandler.execute(req); + }), contentStream, counter.getCount()); return result.map(result1 -> { Result toReturn = result.get(); diff --git a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java index aec7ebd75..0fe0ace05 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java +++ b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java @@ -32,7 +32,7 @@ import org.openqa.selenium.interactions.KeyInput; import org.openqa.selenium.interactions.Sequence; -import org.openqa.selenium.remote.http.W3CHttpCommandCodec; +import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; import java.util.Collection; import java.util.Map; diff --git a/src/main/java/io/appium/java_client/remote/MobileOptions.java b/src/main/java/io/appium/java_client/remote/MobileOptions.java index 6a7810f1a..bf8ea1f38 100644 --- a/src/main/java/io/appium/java_client/remote/MobileOptions.java +++ b/src/main/java/io/appium/java_client/remote/MobileOptions.java @@ -18,6 +18,7 @@ import org.openqa.selenium.Capabilities; import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.Platform; import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.remote.CapabilityType; @@ -38,7 +39,7 @@ public MobileOptions() { * @param source is Capabilities instance to merge into new instance */ public MobileOptions(Capabilities source) { - merge(source); + super(source); } /** @@ -52,16 +53,6 @@ public T setPlatformName(String platform) { return amend(CapabilityType.PLATFORM_NAME, platform); } - /** - * Get the kind of mobile device or emulator to use. - * - * @return String representing the kind of mobile device or emulator to use. - * @see org.openqa.selenium.remote.CapabilityType#PLATFORM_NAME - */ - public String getPlatformName() { - return (String) getCapability(CapabilityType.PLATFORM_NAME); - } - /** * Set the absolute local path for the location of the App. * The or remote http URL to a {@code .ipa} file (IOS), diff --git a/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java b/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java index 3e82e0de4..37851fd4b 100644 --- a/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java +++ b/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java @@ -22,8 +22,6 @@ import static org.slf4j.event.Level.INFO; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.apache.commons.lang3.StringUtils; @@ -42,6 +40,7 @@ import java.net.URL; import java.time.Duration; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; import java.util.function.BiConsumer; @@ -61,25 +60,22 @@ public final class AppiumDriverLocalService extends DriverService { private static final Duration DESTROY_TIMEOUT = Duration.ofSeconds(60); private final File nodeJSExec; - private final ImmutableList nodeJSArgs; - private final ImmutableMap nodeJSEnvironment; - private final long startupTimeout; - private final TimeUnit timeUnit; + private final List nodeJSArgs; + private final Map nodeJSEnvironment; + private final Duration startupTimeout; private final ReentrantLock lock = new ReentrantLock(true); //uses "fair" thread ordering policy private final ListOutputStream stream = new ListOutputStream().add(System.out); private final URL url; private CommandLine process = null; - AppiumDriverLocalService(String ipAddress, File nodeJSExec, int nodeJSPort, - ImmutableList nodeJSArgs, ImmutableMap nodeJSEnvironment, - long startupTimeout, TimeUnit timeUnit) throws IOException { - super(nodeJSExec, nodeJSPort, nodeJSArgs, nodeJSEnvironment); + AppiumDriverLocalService(String ipAddress, File nodeJSExec, int nodeJSPort, Duration startupTimeout, + List nodeJSArgs, Map nodeJSEnvironment) throws IOException { + super(nodeJSExec, nodeJSPort, startupTimeout, nodeJSArgs, nodeJSEnvironment); this.nodeJSExec = nodeJSExec; this.nodeJSArgs = nodeJSArgs; this.nodeJSEnvironment = nodeJSEnvironment; this.startupTimeout = startupTimeout; - this.timeUnit = timeUnit; this.url = new URL(String.format(URL_MASK, ipAddress, nodeJSPort)); } @@ -114,7 +110,7 @@ public boolean isRunning() { } try { - ping(1500, TimeUnit.MILLISECONDS); + ping(Duration.ofMillis(1500)); return true; } catch (UrlChecker.TimeoutException e) { return false; @@ -127,10 +123,10 @@ public boolean isRunning() { } - private void ping(long time, TimeUnit timeUnit) throws UrlChecker.TimeoutException, MalformedURLException { + private void ping(Duration timeout) throws UrlChecker.TimeoutException, MalformedURLException { // The operating system might block direct access to the universal broadcast IP address URL status = new URL(url.toString().replace(BROADCAST_IP_ADDRESS, "127.0.0.1") + "/status"); - new UrlChecker().waitUntilAvailable(time, timeUnit, status); + new UrlChecker().waitUntilAvailable(timeout.toMillis(), TimeUnit.MILLISECONDS, status); } /** @@ -152,7 +148,7 @@ public void start() throws AppiumServerHasNotBeenStartedLocallyException { process.setEnvironmentVariables(nodeJSEnvironment); process.copyOutputTo(stream); process.executeAsync(); - ping(startupTimeout, timeUnit); + ping(startupTimeout); } catch (Throwable e) { destroyProcess(); String msgTxt = "The local appium server has not been started. " diff --git a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java index dc9b669be..30147838e 100644 --- a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java +++ b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java @@ -21,7 +21,6 @@ import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -36,6 +35,7 @@ import org.openqa.selenium.Capabilities; import org.openqa.selenium.Platform; import org.openqa.selenium.os.ExecutableFinder; +import org.openqa.selenium.remote.Browser; import org.openqa.selenium.remote.BrowserType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.service.DriverService; @@ -47,6 +47,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -87,9 +88,6 @@ public final class AppiumServiceBuilder private static final Function NODE_JS_NOT_EXIST_ERROR = (fullPath) -> String.format("The main NodeJS executable does not exist at '%s'", fullPath.getAbsolutePath()); - // The first starting is slow sometimes on some environment - private long startupTimeout = 120; - private TimeUnit timeUnit = TimeUnit.SECONDS; private static final List PATH_CAPABILITIES = ImmutableList.of(AndroidMobileCapabilityType.KEYSTORE_PATH, AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE, MobileCapabilityType.APP); @@ -116,8 +114,8 @@ public int score(Capabilities capabilities) { } String browserName = capabilities.getBrowserName(); - if (browserName.equals(BrowserType.CHROME) || browserName.equals(BrowserType.ANDROID) - || browserName.equals(BrowserType.SAFARI)) { + if (Browser.CHROME.is(browserName) || browserName.equals(BrowserType.ANDROID) + || Browser.SAFARI.is(browserName)) { score++; } @@ -277,21 +275,6 @@ public AppiumServiceBuilder withIPAddress(String ipAddress) { return this; } - /** - * Sets start up timeout. - * - * @param time a time value for the service starting up. - * @param timeUnit a time unit for the service starting up. - * @return self-reference. - */ - public AppiumServiceBuilder withStartUpTimeOut(long time, TimeUnit timeUnit) { - checkNotNull(timeUnit); - checkArgument(time > 0, "Time value should be greater than zero", time); - this.startupTimeout = time; - this.timeUnit = timeUnit; - return this; - } - @Nullable private static File loadPathFromEnv(String envVarName) { String fullPath = System.getProperty(envVarName); @@ -474,11 +457,12 @@ public AppiumServiceBuilder withLogFile(File logFile) { @Override protected AppiumDriverLocalService createDriverService(File nodeJSExecutable, int nodeJSPort, - ImmutableList nodeArguments, - ImmutableMap nodeEnvironment) { + Duration startupTimeout, + List nodeArguments, + Map nodeEnvironment) { try { - return new AppiumDriverLocalService(ipAddress, nodeJSExecutable, nodeJSPort, - nodeArguments, nodeEnvironment, startupTimeout, timeUnit); + return new AppiumDriverLocalService(ipAddress, nodeJSExecutable, nodeJSPort, startupTimeout, nodeArguments, + nodeEnvironment); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/io/appium/java_client/touch/offset/ElementOption.java b/src/main/java/io/appium/java_client/touch/offset/ElementOption.java index ede90103c..775b067d1 100644 --- a/src/main/java/io/appium/java_client/touch/offset/ElementOption.java +++ b/src/main/java/io/appium/java_client/touch/offset/ElementOption.java @@ -6,7 +6,7 @@ import org.openqa.selenium.Point; import org.openqa.selenium.WebElement; -import org.openqa.selenium.internal.HasIdentity; +import org.openqa.selenium.remote.RemoteWebElement; import java.util.HashMap; import java.util.Map; @@ -84,9 +84,9 @@ public ElementOption withCoordinates(int xOffset, int yOffset) { public ElementOption withElement(WebElement element) { checkNotNull(element); checkArgument(true, "Element should be an instance of the class which " - + "implements org.openqa.selenium.internal.HasIdentity", - element instanceof HasIdentity); - elementId = ((HasIdentity) element).getId(); + + "extends org.openqa.selenium.remote.RemoteWebElement", + element instanceof RemoteWebElement); + elementId = ((RemoteWebElement) element).getId(); return this; } diff --git a/src/main/java/io/appium/java_client/windows/WindowsDriver.java b/src/main/java/io/appium/java_client/windows/WindowsDriver.java index 3c8126ac1..cf89449de 100644 --- a/src/main/java/io/appium/java_client/windows/WindowsDriver.java +++ b/src/main/java/io/appium/java_client/windows/WindowsDriver.java @@ -19,7 +19,6 @@ import static io.appium.java_client.remote.MobilePlatform.WINDOWS; import io.appium.java_client.AppiumDriver; -import io.appium.java_client.FindsByWindowsAutomation; import io.appium.java_client.HidesKeyboardWithKeyName; import io.appium.java_client.screenrecording.CanRecordScreen; import io.appium.java_client.service.local.AppiumDriverLocalService; @@ -32,8 +31,7 @@ import java.net.URL; public class WindowsDriver - extends AppiumDriver implements PressesKeyCode, HidesKeyboardWithKeyName, - FindsByWindowsAutomation, CanRecordScreen { + extends AppiumDriver implements PressesKeyCode, HidesKeyboardWithKeyName, CanRecordScreen { public WindowsDriver(HttpCommandExecutor executor, Capabilities capabilities) { super(executor, updateDefaultPlatformName(capabilities, WINDOWS)); diff --git a/src/main/java/io/appium/java_client/windows/WindowsElement.java b/src/main/java/io/appium/java_client/windows/WindowsElement.java index 4f7ec7ba2..ad5d3a5d8 100644 --- a/src/main/java/io/appium/java_client/windows/WindowsElement.java +++ b/src/main/java/io/appium/java_client/windows/WindowsElement.java @@ -16,8 +16,7 @@ package io.appium.java_client.windows; -import io.appium.java_client.FindsByWindowsAutomation; import io.appium.java_client.MobileElement; -public class WindowsElement extends MobileElement implements FindsByWindowsAutomation { +public class WindowsElement extends MobileElement { } diff --git a/src/main/java/io/appium/java_client/ws/StringWebSocketClient.java b/src/main/java/io/appium/java_client/ws/StringWebSocketClient.java index d7ebe559e..6a3148aa2 100644 --- a/src/main/java/io/appium/java_client/ws/StringWebSocketClient.java +++ b/src/main/java/io/appium/java_client/ws/StringWebSocketClient.java @@ -16,21 +16,21 @@ package io.appium.java_client.ws; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.WebSocket; -import okhttp3.WebSocketListener; - import java.net.URI; +import java.time.Duration; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import javax.annotation.Nullable; -public class StringWebSocketClient extends WebSocketListener implements +import org.openqa.selenium.remote.http.ClientConfig; +import org.openqa.selenium.remote.http.HttpClient; +import org.openqa.selenium.remote.http.HttpMethod; +import org.openqa.selenium.remote.http.HttpRequest; +import org.openqa.selenium.remote.http.WebSocket; + +public class StringWebSocketClient implements WebSocket.Listener, CanHandleMessages, CanHandleErrors, CanHandleConnects, CanHandleDisconnects { private final List> messageHandlers = new CopyOnWriteArrayList<>(); private final List> errorHandlers = new CopyOnWriteArrayList<>(); @@ -65,37 +65,36 @@ public void connect(URI endpoint) { return; } - OkHttpClient client = new OkHttpClient.Builder() - .readTimeout(0, TimeUnit.MILLISECONDS) - .build(); - Request request = new Request.Builder() - .url(endpoint.toString()) - .build(); - client.newWebSocket(request, this); - client.dispatcher().executorService().shutdown(); + ClientConfig clientConfig = ClientConfig.defaultConfig() + .readTimeout(Duration.ZERO) + .baseUri(endpoint); // To avoid NPE in org.openqa.selenium.remote.http.netty.NettyMessages (line 78) + HttpClient client = HttpClient.Factory.createDefault().createClient(clientConfig); + HttpRequest request = new HttpRequest(HttpMethod.GET, endpoint.toString()); + client.openSocket(request, this); + onOpen(); setEndpoint(endpoint); } - @Override - public void onOpen(WebSocket webSocket, Response response) { + public void onOpen() { getConnectionHandlers().forEach(Runnable::run); isListening = true; } @Override - public void onClosing(WebSocket webSocket, int code, String reason) { + public void onClose(int code, String reason) { getDisconnectionHandlers().forEach(Runnable::run); isListening = false; } @Override - public void onFailure(WebSocket webSocket, Throwable t, Response response) { + public void onError(Throwable t) { getErrorHandlers().forEach(x -> x.accept(t)); } @Override - public void onMessage(WebSocket webSocket, String text) { + public void onText(CharSequence data) { + String text = data.toString(); getMessageHandlers().forEach(x -> x.accept(text)); } diff --git a/src/main/java/org/openqa/selenium/WebDriver.java b/src/main/java/org/openqa/selenium/WebDriver.java index 08de94859..c8f990896 100644 --- a/src/main/java/org/openqa/selenium/WebDriver.java +++ b/src/main/java/org/openqa/selenium/WebDriver.java @@ -21,14 +21,15 @@ import org.openqa.selenium.logging.Logs; import java.net.URL; +import java.time.Duration; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; /** - * The main interface to use for testing, which represents an idealised web browser. The methods in - * this class fall into three categories: + * WebDriver is a remote control interface that enables introspection and control of user agents + * (browsers). The methods in this interface fall into three categories: *
    *
  • Control of the browser itself
  • *
  • Selection of {@link WebElement}s
  • @@ -39,31 +40,38 @@ * various methods similar to {@link WebDriver#findElement(By)}, which is used to find * {@link WebElement}s. *

    - * Currently, you will need to instantiate implementations of this class directly. It is hoped that - * you write your tests against this interface so that you may "swap in" a more fully featured + * Currently, you will need to instantiate implementations of this interface directly. It is hoped + * that you write your tests against this interface so that you may "swap in" a more fully featured * browser when there is a requirement for one. *

    - * Note that all methods that use XPath to locate elements will throw a {@link RuntimeException} - * should there be an error thrown by the underlying XPath engine. + * Most implementations of this interface follow + * W3C WebDriver specification */ public interface WebDriver extends SearchContext { // Navigation /** - * Load a new web page in the current browser window. This is done using an HTTP GET operation, - * and the method will block until the load is complete. This will follow redirects issued either - * by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect - * "rest" for any duration of time, it is best to wait until this timeout is over, since should - * the underlying page change whilst your test is executing the results of future calls against - * this interface will be against the freshly loaded page. Synonym for - * {@link org.openqa.selenium.WebDriver.Navigation#to(String)}. + * Load a new web page in the current browser window. This is done using an HTTP POST operation, + * and the method will block until the load is complete (with the default 'page load strategy'. + * This will follow redirects issued either by the server or as a meta-redirect from within the + * returned HTML. Should a meta-redirect "rest" for any duration of time, it is best to wait until + * this timeout is over, since should the underlying page change whilst your test is executing the + * results of future calls against this interface will be against the freshly loaded page. Synonym + * for {@link org.openqa.selenium.WebDriver.Navigation#to(String)}. + *

    + * See W3C WebDriver specification + * for more details. * - * @param url The URL to load. It is best to use a fully qualified URL + * @param url The URL to load. Must be a fully qualified URL + * @see org.openqa.selenium.PageLoadStrategy */ void get(String url); /** * Get a string representing the current URL that the browser is looking at. + *

    + * See W3C WebDriver specification + * for more details. * * @return The URL of the page currently loaded in the browser */ @@ -72,7 +80,10 @@ public interface WebDriver extends SearchContext { // General properties /** - * The title of the current page. + * Get the title of the current page. + *

    + * See W3C WebDriver specification + * for more details. * * @return The title of the current page, with leading and trailing whitespace stripped, or null * if one is not already set @@ -84,13 +95,17 @@ public interface WebDriver extends SearchContext { * This method is affected by the 'implicit wait' times in force at the time of execution. When * implicitly waiting, this method will return as soon as there are more than 0 items in the * found collection, or will return an empty list if the timeout is reached. + *

    + * See W3C WebDriver specification + * for more details. * * @param by The locating mechanism to use - * @return A list of all {@link WebElement}s, or an empty list if nothing matches + * @return A list of all matching {@link WebElement}s, or an empty list if nothing matches * @see org.openqa.selenium.By * @see org.openqa.selenium.WebDriver.Timeouts */ - List findElements(By by); + @Override + List findElements(By by); /** @@ -98,16 +113,20 @@ public interface WebDriver extends SearchContext { * This method is affected by the 'implicit wait' times in force at the time of execution. * The findElement(..) invocation will return a matching row, or try again repeatedly until * the configured timeout is reached. - * + *

    * findElement should not be used to look for non-present elements, use {@link #findElements(By)} * and assert zero length response instead. + *

    + * See W3C WebDriver specification + * for more details. * - * @param by The locating mechanism + * @param by The locating mechanism to use * @return The first matching element on the current page * @throws NoSuchElementException If no matching elements are found * @see org.openqa.selenium.By * @see org.openqa.selenium.WebDriver.Timeouts */ + @Override T findElement(By by); // Misc @@ -118,8 +137,11 @@ public interface WebDriver extends SearchContext { * page. Please consult the documentation of the particular driver being used to determine whether * the returned text reflects the current state of the page or the text last sent by the web * server. The page source returned is a representation of the underlying DOM: do not expect it to - * be formatted or escaped in the same way as the response sent from the web server. Think of it as - * an artist's impression. + * be formatted or escaped in the same way as the response sent from the web server. Think of it + * as an artist's impression. + *

    + * See W3C WebDriver specification + * for more details. * * @return The source of the current page */ @@ -127,6 +149,9 @@ public interface WebDriver extends SearchContext { /** * Close the current window, quitting the browser if it's the last window currently open. + *

    + * See W3C WebDriver specification + * for more details. */ void close(); @@ -138,6 +163,9 @@ public interface WebDriver extends SearchContext { /** * Return a set of window handles which can be used to iterate over all open windows of this * WebDriver instance by passing them to {@link #switchTo()}.{@link Options#window()} + *

    + * See W3C WebDriver specification + * for more details. * * @return A set of window handles which can be used to iterate over all open windows. */ @@ -146,6 +174,9 @@ public interface WebDriver extends SearchContext { /** * Return an opaque handle to this window that uniquely identifies it within this driver instance. * This can be used to switch to this window at a later date + *

    + * See W3C WebDriver specification + * for more details. * * @return the current window handle */ @@ -184,6 +215,9 @@ interface Options { /** * Add a specific cookie. If the cookie's domain name is left blank, it is assumed that the * cookie is meant for the domain of the current document. + *

    + * See W3C WebDriver specification + * for more details. * * @param cookie The cookie to add. */ @@ -192,6 +226,9 @@ interface Options { /** * Delete the named cookie from the current domain. This is equivalent to setting the named * cookie's expiry date to some time in the past. + *

    + * See W3C WebDriver specification + * for more details. * * @param name The name of the cookie to delete */ @@ -206,12 +243,17 @@ interface Options { /** * Delete all the cookies for the current domain. + *

    + * See W3C WebDriver specification + * for more details. */ void deleteAllCookies(); /** - * Get all the cookies for the current domain. This is the equivalent of calling - * "document.cookie" and parsing the result + * Get all the cookies for the current domain. + *

    + * See W3C WebDriver specification + * for more details. * * @return A Set of cookies for the current domain. */ @@ -219,6 +261,9 @@ interface Options { /** * Get a cookie with a given name. + *

    + * See W3C WebDriver specification + * for more details. * * @param name the name of the cookie * @return the cookie, or null if no cookie with the given name is present @@ -242,8 +287,8 @@ interface Options { /** * Gets the {@link Logs} interface used to fetch different types of logs. - * - *

    To set the logging preferences {@link LoggingPreferences}. + *

    + * To set the logging preferences {@link LoggingPreferences}. * * @return A Logs interface. */ @@ -253,10 +298,15 @@ interface Options { /** * An interface for managing timeout behavior for WebDriver instances. + *

    + * See W3C WebDriver specification + * for more details. */ interface Timeouts { /** + * @deprecated Use {@link #implicitlyWait(Duration)} + * * Specifies the amount of time the driver should wait when searching for an element if it is * not immediately present. *

    @@ -267,34 +317,153 @@ interface Timeouts { *

    * Increasing the implicit wait timeout should be used judiciously as it will have an adverse * effect on test run time, especially when used with slower location strategies like XPath. + *

    + * If the timeout is negative, not null, or greater than 2e16 - 1, an error code with invalid + * argument will be returned. * * @param time The amount of time to wait. * @param unit The unit of measure for {@code time}. * @return A self reference. */ + @Deprecated Timeouts implicitlyWait(long time, TimeUnit unit); /** + * Specifies the amount of time the driver should wait when searching for an element if it is + * not immediately present. + *

    + * When searching for a single element, the driver should poll the page until the element has + * been found, or this timeout expires before throwing a {@link NoSuchElementException}. When + * searching for multiple elements, the driver should poll the page until at least one element + * has been found or this timeout has expired. + *

    + * Increasing the implicit wait timeout should be used judiciously as it will have an adverse + * effect on test run time, especially when used with slower location strategies like XPath. + *

    + * If the timeout is negative, not null, or greater than 2e16 - 1, an error code with invalid + * argument will be returned. + * + * @param duration The duration to wait. + * @return A self reference. + */ + default Timeouts implicitlyWait(Duration duration) { + return implicitlyWait(duration.toMillis(), TimeUnit.MILLISECONDS); + } + + /** + * Gets the amount of time the driver should wait when searching for an element if it is + * not immediately present. + * + * @return The amount of time the driver should wait when searching for an element. + * @see W3C WebDriver + */ + default Duration getImplicitWaitTimeout() { + throw new UnsupportedCommandException(); + } + + /** + * @deprecated Use {@link #setScriptTimeout(Duration)} + * * Sets the amount of time to wait for an asynchronous script to finish execution before - * throwing an error. If the timeout is negative, then the script will be allowed to run - * indefinitely. + * throwing an error. If the timeout is negative, not null, or greater than 2e16 - 1, an + * error code with invalid argument will be returned. * * @param time The timeout value. * @param unit The unit of time. * @return A self reference. * @see JavascriptExecutor#executeAsyncScript(String, Object...) + * @see W3C WebDriver + * @see W3C WebDriver */ + @Deprecated Timeouts setScriptTimeout(long time, TimeUnit unit); /** - * Sets the amount of time to wait for a page load to complete before throwing an error. - * If the timeout is negative, page loads can be indefinite. + * Sets the amount of time to wait for an asynchronous script to finish execution before + * throwing an error. If the timeout is negative, not null, or greater than 2e16 - 1, an + * error code with invalid argument will be returned. * + * @param duration The timeout value. + * @deprecated Use {@link #scriptTimeout(Duration)} + * @return A self reference. + * @see JavascriptExecutor#executeAsyncScript(String, Object...) + * @see W3C WebDriver + * @see W3C WebDriver + */ + @Deprecated + default Timeouts setScriptTimeout(Duration duration) { + return setScriptTimeout(duration.toMillis(), TimeUnit.MILLISECONDS); + } + + /** + * Sets the amount of time to wait for an asynchronous script to finish execution before + * throwing an error. If the timeout is negative, not null, or greater than 2e16 - 1, an + * error code with invalid argument will be returned. + * + * @param duration The timeout value. + * @return A self reference. + * @see JavascriptExecutor#executeAsyncScript(String, Object...) + * @see W3C WebDriver + * @see W3C WebDriver + */ + default Timeouts scriptTimeout(Duration duration) { + return setScriptTimeout(duration); + } + + /** + * Gets the amount of time to wait for an asynchronous script to finish execution before + * throwing an error. If the timeout is negative, not null, or greater than 2e16 - 1, an + * error code with invalid argument will be returned. + * + * @return The amount of time to wait for an asynchronous script to finish execution. + * @see W3C WebDriver + * @see W3C WebDriver + */ + default Duration getScriptTimeout() { + throw new UnsupportedCommandException(); + } + + /** * @param time The timeout value. * @param unit The unit of time. * @return A Timeouts interface. + * @see W3C WebDriver + * @see W3C WebDriver + * @deprecated Use {@link #pageLoadTimeout(Duration)} + * + * Sets the amount of time to wait for a page load to complete before throwing an error. + * If the timeout is negative, not null, or greater than 2e16 - 1, an error code with + * invalid argument will be returned. */ + @Deprecated Timeouts pageLoadTimeout(long time, TimeUnit unit); + + /** + * Sets the amount of time to wait for a page load to complete before throwing an error. + * If the timeout is negative, not null, or greater than 2e16 - 1, an error code with + * invalid argument will be returned. + * + * @param duration The timeout value. + * @return A Timeouts interface. + * @see W3C WebDriver + * @see W3C WebDriver + */ + default Timeouts pageLoadTimeout(Duration duration) { + return pageLoadTimeout(duration.toMillis(), TimeUnit.MILLISECONDS); + } + + /** + * Gets the amount of time to wait for a page load to complete before throwing an error. + * If the timeout is negative, not null, or greater than 2e16 - 1, an error code with + * invalid argument will be returned. + * + * @return The amount of time to wait for a page load to complete. + * @see W3C WebDriver + * @see W3C WebDriver + */ + default Duration getPageLoadTimeout() { + throw new UnsupportedCommandException(); + } } /** @@ -306,6 +475,9 @@ interface TargetLocator { * JS expression window.frames[index] where "window" is the DOM window represented by the * current context. Once the frame has been selected, all subsequent calls on the WebDriver * interface are made to that frame. + *

    + * See W3C WebDriver specification + * for more details. * * @param index (zero-based) index * @return This driver focused on the given frame @@ -326,6 +498,9 @@ interface TargetLocator { /** * Select a frame using its previously located {@link WebElement}. + *

    + * See W3C WebDriver specification + * for more details. * * @param frameElement The frame element to switch to. * @return This driver focused on the given frame. @@ -338,6 +513,9 @@ interface TargetLocator { /** * Change focus to the parent context. If the current context is the top level browsing context, * the context remains unchanged. + *

    + * See W3C WebDriver specification + * for more details. * * @return This driver focused on the parent frame */ @@ -345,6 +523,9 @@ interface TargetLocator { /** * Switch the focus of future commands for this driver to the window with the given name/handle. + *

    + * See W3C WebDriver specification + * for more details. * * @param nameOrHandle The name of the window or the handle as returned by * {@link WebDriver#getWindowHandle()} @@ -353,9 +534,27 @@ interface TargetLocator { */ WebDriver window(String nameOrHandle); + /** + * Creates a new browser window and switches the focus for future commands of this driver + * to the new window. + *

    + * See W3C WebDriver specification + * for more details. + * + * @param typeHint The type of new browser window to be created. The created window is not + * guaranteed to be of the requested type; if the driver does not support + * the requested type, a new browser window will be created of whatever type + * the driver does support. + * @return This driver focused on the given window + */ + WebDriver newWindow(WindowType typeHint); + /** * Selects either the first frame on the page, or the main document when a page contains * iframes. + *

    + * See W3C WebDriver specification + * for more details. * * @return This driver focused on the top window/first frame. */ @@ -365,6 +564,9 @@ interface TargetLocator { * Switches to the element that currently has focus within the document currently "switched to", * or the body element if this cannot be detected. This matches the semantics of calling * "document.activeElement" in Javascript. + *

    + * See W3C WebDriver specification + * for more details. * * @return The WebElement with focus, or the body element if no element with focus can be * detected. @@ -383,25 +585,34 @@ interface TargetLocator { interface Navigation { /** * Move back a single "item" in the browser's history. + *

    + * See W3C WebDriver specification + * for more details. */ void back(); /** * Move a single "item" forward in the browser's history. Does nothing if we are on the latest * page viewed. + *

    + * See W3C WebDriver specification + * for more details. */ void forward(); /** - * Load a new web page in the current browser window. This is done using an HTTP GET operation, + * Load a new web page in the current browser window. This is done using an HTTP POST operation, * and the method will block until the load is complete. This will follow redirects issued * either by the server or as a meta-redirect from within the returned HTML. Should a * meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over, * since should the underlying page change whilst your test is executing the results of future * calls against this interface will be against the freshly loaded page. + *

    + * See W3C WebDriver specification + * for more details. * - * @param url The URL to load. It is best to use a fully qualified URL + * @param url The URL to load. Must be a fully qualified URL */ void to(String url); @@ -414,6 +625,9 @@ interface Navigation { /** * Refresh the current page + *

    + * See W3C WebDriver specification + * for more details. */ void refresh(); } @@ -457,7 +671,7 @@ interface ImeHandler { /** * Make an engines that is available (appears on the list returned by getAvailableEngines) * active. After this call, the only loaded engine on the IME daemon will be this one and the - * input sent using sendKeys will be converted by the engine. Noteh that this is a + * input sent using sendKeys will be converted by the engine. Note that this is a * platform-independent method of activating IME (the platform-specific way being using keyboard * shortcuts). * @@ -472,45 +686,72 @@ interface ImeHandler { @Beta interface Window { + + /** + * Get the size of the current window. This will return the outer window dimension, not just + * the view port. + *

    + * See W3C WebDriver specification + * for more details. + * + * @return The current window size. + */ + Dimension getSize(); + /** * Set the size of the current window. This will change the outer window dimension, * not just the view port, synonymous to window.resizeTo() in JS. + *

    + * See W3C WebDriver specification + * for more details. * * @param targetSize The target size. */ void setSize(Dimension targetSize); /** - * Set the position of the current window. This is relative to the upper left corner of the - * screen, synonymous to window.moveTo() in JS. + * Get the position of the current window, relative to the upper left corner of the screen. + *

    + * See W3C WebDriver specification + * for more details. * - * @param targetPosition The target position of the window. + * @return The current window position. */ - void setPosition(Point targetPosition); + Point getPosition(); /** - * Get the size of the current window. This will return the outer window dimension, not just - * the view port. + * Set the position of the current window. This is relative to the upper left corner of the + * screen, synonymous to window.moveTo() in JS. + *

    + * See W3C WebDriver specification + * for more details. * - * @return The current window size. + * @param targetPosition The target position of the window. */ - Dimension getSize(); + void setPosition(Point targetPosition); /** - * Get the position of the current window, relative to the upper left corner of the screen. - * - * @return The current window position. + * Maximizes the current window if it is not already maximized + *

    + * See W3C WebDriver specification + * for more details. */ - Point getPosition(); + void maximize(); /** - * Maximizes the current window if it is not already maximized + * Minimizes the current window if it is not already minimized + *

    + * See W3C WebDriver specification + * for more details. */ - void maximize(); + void minimize(); /** * Fullscreen the current window if it is not already fullscreen + *

    + * See W3C WebDriver specification + * for more details. */ void fullscreen(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/openqa/selenium/WebElement.java b/src/main/java/org/openqa/selenium/WebElement.java index 1aa2da524..ba2e441b7 100644 --- a/src/main/java/org/openqa/selenium/WebElement.java +++ b/src/main/java/org/openqa/selenium/WebElement.java @@ -34,15 +34,18 @@ public interface WebElement extends SearchContext, TakesScreenshot { * should discard all references to this element and any further * operations performed on this element will throw a * StaleElementReferenceException. - * + *

    * Note that if click() is done by sending a native event (which is * the default on most browsers/platforms) then the method will * _not_ wait for the next page to load and the caller should verify * that themselves. - * + *

    * There are some preconditions for an element to be clicked. The * element must be visible and it must have a height and width * greater then 0. + *

    + * See W3C WebDriver specification + * for more details. * * @throws StaleElementReferenceException If the element no * longer exists as initially defined @@ -60,71 +63,143 @@ public interface WebElement extends SearchContext, TakesScreenshot { /** * Use this method to simulate typing into an element, which may set its value. + *

    + * See W3C WebDriver specification + * for more details. * * @param keysToSend character sequence to send to the element + * + * @throws IllegalArgumentException if keysToSend is null */ void sendKeys(CharSequence... keysToSend); /** - * If this element is a text entry element, this will clear the value. Has no effect on other - * elements. Text entry elements are INPUT and TEXTAREA elements. - * - * Note that the events fired by this event may not be as you'd expect. In particular, we don't - * fire any keyboard or mouse events. If you want to ensure keyboard events are fired, consider - * using something like {@link #sendKeys(CharSequence...)} with the backspace key. To ensure - * you get a change event, consider following with a call to {@link #sendKeys(CharSequence...)} - * with the tab key. + * If this element is a form entry element, this will reset its value. + *

    + * See W3C WebDriver specification + * and HTML specification + * for more details. */ void clear(); /** * Get the tag name of this element. Not the value of the name attribute: will return * "input" for the element <input name="foo" />. + *

    + * See W3C WebDriver specification + * for more details. * * @return The tag name of this element. */ String getTagName(); /** - * Get the value of the given attribute of the element. Will return the current value, even if + * Get the value of the given property of the element. Will return the current value, even if * this has been modified after the page has been loaded. + *

    + * See W3C WebDriver specification + * for more details. * - *

    More exactly, this method will return the value of the property with the given name, if it + * @param name The name of the property. + * @return The property's current value or null if the value is not set. + */ + default String getDomProperty(String name) { + throw new UnsupportedOperationException("getDomProperty"); + } + + /** + * Get the value of the given attribute of the element. + *

    + * This method, unlike {@link #getAttribute(String)}, returns the value of the attribute with the + * given name but not the property with the same name. + *

    + * The following are deemed to be "boolean" attributes, and will return either "true" or null: + *

    + * async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, + * defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, + * iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, + * novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, + * seeking, selected, truespeed, willvalidate + *

    + * See W3C WebDriver specification + * for more details. + * + * @param name The name of the attribute. + * @return The attribute's value or null if the value is not set. + */ + default String getDomAttribute(String name) { + throw new UnsupportedOperationException("getDomAttribute"); + } + + /** + * Get the value of the given attribute of the element. Will return the current value, even if + * this has been modified after the page has been loaded. + *

    + * More exactly, this method will return the value of the property with the given name, if it * exists. If it does not, then the value of the attribute with the given name is returned. If * neither exists, null is returned. - * - *

    The "style" attribute is converted as best can be to a text representation with a trailing + *

    + * The "style" attribute is converted as best can be to a text representation with a trailing * semi-colon. - * - *

    The following are deemed to be "boolean" attributes, and will return either "true" or null: - * - *

    async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, + *

    + * The following are deemed to be "boolean" attributes, and will return either "true" or null: + *

    + * async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, * defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, * iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, * novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, * seeking, selected, truespeed, willvalidate - * - *

    Finally, the following commonly mis-capitalized attribute/property names are evaluated as + *

    + * Finally, the following commonly mis-capitalized attribute/property names are evaluated as * expected: - * *

      *
    • If the given name is "class", the "className" property is returned. *
    • If the given name is "readonly", the "readOnly" property is returned. *
    - * * Note: The reason for this behavior is that users frequently confuse attributes and - * properties. If you need to do something more precise, e.g., refer to an attribute even when a - * property of the same name exists, then you should evaluate Javascript to obtain the result - * you desire. + * properties. If you need to do something more precise, use {@link #getDomAttribute(String)} + * or {@link #getDomProperty(String)} to obtain the result you desire. + *

    + * See W3C WebDriver specification + * for more details. * * @param name The name of the attribute. * @return The attribute/property's current value or null if the value is not set. */ String getAttribute(String name); + /** + * Gets result of computing the WAI-ARIA role of element. + *

    + * See W3C WebDriver specification + * for more details. + * + * @return the WAI-ARIA role of the element. + */ + default String getAriaRole() { + throw new UnsupportedOperationException("getAriaRole"); + } + + /** + * Gets result of a Accessible Name and Description Computation for the Accessible Name of the element. + *

    + * See W3C WebDriver specification + * for more details. + * + * @return the accessible name of the element. + */ + default String getAccessibleName() { + throw new UnsupportedOperationException("getAccessibleName"); + } + /** * Determine whether or not this element is selected or not. This operation only applies to input * elements such as checkboxes, options in a select and radio buttons. + * For more information on which elements this method supports, + * refer to the specification. + *

    + * See W3C WebDriver specification + * for more details. * * @return True if the element is currently selected or checked, false otherwise. */ @@ -133,16 +208,21 @@ public interface WebElement extends SearchContext, TakesScreenshot { /** * Is the element currently enabled or not? This will generally return true for everything but * disabled input elements. + *

    + * See W3C WebDriver specification + * for more details. * * @return True if the element is enabled, false otherwise. */ boolean isEnabled(); /** - * Get the visible (i.e. not hidden by CSS) innerText of this element, including sub-elements, - * without any leading or trailing whitespace. + * Get the visible (i.e. not hidden by CSS) text of this element, including sub-elements. + *

    + * See W3C WebDriver specification + * for more details. * - * @return The innerText of this element. + * @return The visible text of this element. */ String getText(); @@ -154,13 +234,17 @@ public interface WebElement extends SearchContext, TakesScreenshot { * This method is affected by the 'implicit wait' times in force at the time of execution. When * implicitly waiting, this method will return as soon as there are more than 0 items in the * found collection, or will return an empty list if the timeout is reached. + *

    + * See W3C WebDriver specification + * for more details. * * @param by The locating mechanism to use * @return A list of all {@link WebElement}s, or an empty list if nothing matches. * @see org.openqa.selenium.By * @see org.openqa.selenium.WebDriver.Timeouts */ - List findElements(By by); + @Override + List findElements(By by); /** * Find the first {@link WebElement} using the given method. See the note in @@ -168,9 +252,12 @@ public interface WebElement extends SearchContext, TakesScreenshot { * This method is affected by the 'implicit wait' times in force at the time of execution. * The findElement(..) invocation will return a matching row, or try again repeatedly until * the configured timeout is reached. - * + *

    * findElement should not be used to look for non-present elements, use {@link #findElements(By)} * and assert zero length response instead. + *

    + * See W3C WebDriver specification + * for more details. * * @param by The locating mechanism * @return The first matching element on the current context. @@ -178,8 +265,17 @@ public interface WebElement extends SearchContext, TakesScreenshot { * @see org.openqa.selenium.By * @see org.openqa.selenium.WebDriver.Timeouts */ + @Override T findElement(By by); + /** + * @return A representation of an element's shadow root for accessing the shadow DOM of a web component. + * @throws NoSuchShadowRootException If no shadow root is found + */ + default SearchContext getShadowRoot() { + throw new UnsupportedOperationException("getShadowRoot"); + } + /** * Is this element displayed or not? This method avoids the problem of having to parse an * element's "style" attribute. @@ -190,6 +286,9 @@ public interface WebElement extends SearchContext, TakesScreenshot { /** * Where on the page is the top left-hand corner of the rendered element? + *

    + * See W3C WebDriver specification + * for more details. * * @return A point, containing the location of the top left-hand corner of the element */ @@ -197,6 +296,9 @@ public interface WebElement extends SearchContext, TakesScreenshot { /** * What is the width and height of the rendered element? + *

    + * See W3C WebDriver specification + * for more details. * * @return The size of the element on the page. */ @@ -204,14 +306,20 @@ public interface WebElement extends SearchContext, TakesScreenshot { /** * @return The location and size of the rendered element + *

    + * See W3C WebDriver specification + * for more details. */ Rectangle getRect(); /** * Get the value of a given CSS property. - * Color values should be returned as rgba strings, so, - * for example if the "background-color" property is set as "green" in the - * HTML source, the returned value will be "rgba(0, 255, 0, 1)". + * Color values could be returned as rgba or rgb strings. + * This depends on whether the browser omits the implicit opacity value or not. + * + * For example if the "background-color" property is set as "green" in the + * HTML source, the returned value could be "rgba(0, 255, 0, 1)" if implicit opacity value is + * preserved or "rgb(0, 255, 0)" if it is omitted. * * Note that shorthand CSS properties (e.g. background, font, border, border-top, margin, * margin-top, padding, padding-top, list-style, outline, pause, cue) are not returned, @@ -219,9 +327,12 @@ public interface WebElement extends SearchContext, TakesScreenshot { * DOM CSS2 specification * - you should directly access the longhand properties (e.g. background-color) to access the * desired values. + *

    + * See W3C WebDriver specification + * for more details. * * @param propertyName the css property name of the element * @return The current, computed value of the property. */ String getCssValue(String propertyName); -} \ No newline at end of file +} diff --git a/src/main/java/org/openqa/selenium/internal/FindsByClassName.java b/src/main/java/org/openqa/selenium/internal/FindsByClassName.java deleted file mode 100644 index cc28072ec..000000000 --- a/src/main/java/org/openqa/selenium/internal/FindsByClassName.java +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you 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; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByClassName { - T findElementByClassName(String using); - - List findElementsByClassName(String using); -} diff --git a/src/main/java/org/openqa/selenium/internal/FindsByCssSelector.java b/src/main/java/org/openqa/selenium/internal/FindsByCssSelector.java deleted file mode 100644 index 74074e534..000000000 --- a/src/main/java/org/openqa/selenium/internal/FindsByCssSelector.java +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you 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; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByCssSelector { - T findElementByCssSelector(String using); - - List findElementsByCssSelector(String using); -} diff --git a/src/main/java/org/openqa/selenium/internal/FindsById.java b/src/main/java/org/openqa/selenium/internal/FindsById.java deleted file mode 100644 index ee4fdd9d3..000000000 --- a/src/main/java/org/openqa/selenium/internal/FindsById.java +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you 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; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsById { - T findElementById(String using); - - List findElementsById(String using); -} diff --git a/src/main/java/org/openqa/selenium/internal/FindsByLinkText.java b/src/main/java/org/openqa/selenium/internal/FindsByLinkText.java deleted file mode 100644 index 52c09f6a1..000000000 --- a/src/main/java/org/openqa/selenium/internal/FindsByLinkText.java +++ /dev/null @@ -1,32 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you 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; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByLinkText { - T findElementByLinkText(String using); - - List findElementsByLinkText(String using); - - T findElementByPartialLinkText(String using); - - List findElementsByPartialLinkText(String using); -} diff --git a/src/main/java/org/openqa/selenium/internal/FindsByName.java b/src/main/java/org/openqa/selenium/internal/FindsByName.java deleted file mode 100644 index 7d39ac1d8..000000000 --- a/src/main/java/org/openqa/selenium/internal/FindsByName.java +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you 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; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByName { - T findElementByName(String using); - - List findElementsByName(String using); -} diff --git a/src/main/java/org/openqa/selenium/internal/FindsByTagName.java b/src/main/java/org/openqa/selenium/internal/FindsByTagName.java deleted file mode 100644 index f5df666af..000000000 --- a/src/main/java/org/openqa/selenium/internal/FindsByTagName.java +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you 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; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByTagName { - T findElementByTagName(String using); - - List findElementsByTagName(String using); -} diff --git a/src/main/java/org/openqa/selenium/internal/FindsByXPath.java b/src/main/java/org/openqa/selenium/internal/FindsByXPath.java deleted file mode 100644 index bea6007cb..000000000 --- a/src/main/java/org/openqa/selenium/internal/FindsByXPath.java +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you 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; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByXPath { - T findElementByXPath(String using); - - List findElementsByXPath(String using); -} diff --git a/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java b/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java index e45b30253..198056e5d 100644 --- a/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java @@ -5,10 +5,12 @@ import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertNotEquals; +import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; import io.appium.java_client.functions.ActionSupplier; import io.appium.java_client.touch.offset.ElementOption; import org.junit.Test; +import org.openqa.selenium.By; import org.openqa.selenium.Point; import java.util.List; @@ -16,11 +18,10 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest { private final ActionSupplier horizontalSwipe = () -> { - driver.findElementById("io.appium.android.apis:id/gallery"); + driver.findElement(By.id("io.appium.android.apis:id/gallery")); - AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery"); - List images = gallery - .findElementsByClassName("android.widget.ImageView"); + AndroidElement gallery = driver.findElement(By.id("io.appium.android.apis:id/gallery")); + List images = gallery.findElements(MobileBy.className("android.widget.ImageView")); Point location = gallery.getLocation(); Point center = gallery.getCenter(); @@ -36,34 +37,33 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest { private final ActionSupplier verticalSwiping = () -> new AndroidTouchAction(driver) - .press(element(driver.findElementByAccessibilityId("Gallery"))) + .press(element(driver.findElement(MobileBy.AccessibilityId("Gallery")))) .waitAction(waitOptions(ofSeconds(2))) - .moveTo(element(driver.findElementByAccessibilityId("Auto Complete"))) + .moveTo(element(driver.findElement(MobileBy.AccessibilityId("Auto Complete")))) .release(); @Test public void horizontalSwipingWithSupplier() { Activity activity = new Activity("io.appium.android.apis", ".view.Gallery1"); driver.startActivity(activity); - AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery"); - List images = gallery - .findElementsByClassName("android.widget.ImageView"); + AndroidElement gallery = driver.findElement(By.id("io.appium.android.apis:id/gallery")); + List images = gallery.findElements(MobileBy.className("android.widget.ImageView")); int originalImageCount = images.size(); horizontalSwipe.get().perform(); - assertNotEquals(originalImageCount, gallery - .findElementsByClassName("android.widget.ImageView").size()); + assertNotEquals(originalImageCount, + gallery.findElements(MobileBy.className("android.widget.ImageView")).size()); } @Test public void verticalSwipingWithSupplier() throws Exception { driver.resetApp(); - driver.findElementByAccessibilityId("Views").click(); + driver.findElement(MobileBy.AccessibilityId("Views")).click(); - Point originalLocation = driver.findElementByAccessibilityId("Gallery").getLocation(); + Point originalLocation = driver.findElement(MobileBy.AccessibilityId("Gallery")).getLocation(); verticalSwiping.get().perform(); Thread.sleep(5000); - assertNotEquals(originalLocation, driver.findElementByAccessibilityId("Gallery").getLocation()); + assertNotEquals(originalLocation, driver.findElement(MobileBy.AccessibilityId("Gallery")).getLocation()); } } diff --git a/src/test/java/io/appium/java_client/android/AndroidElementTest.java b/src/test/java/io/appium/java_client/android/AndroidElementTest.java index 50bed4895..cb89f258f 100644 --- a/src/test/java/io/appium/java_client/android/AndroidElementTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidElementTest.java @@ -35,20 +35,20 @@ public class AndroidElementTest extends BaseAndroidTest { @Test public void findByAccessibilityIdTest() { - assertNotEquals(driver.findElementById("android:id/content") + assertNotEquals(driver.findElement(By.id("android:id/content")) .findElement(MobileBy.AccessibilityId("Graphics")).getText(), null); - assertEquals(driver.findElementById("android:id/content") + assertEquals(driver.findElement(By.id("android:id/content")) .findElements(MobileBy.AccessibilityId("Graphics")).size(), 1); } @Test public void findByAndroidUIAutomatorTest() { - assertNotEquals(driver.findElementById("android:id/content") + assertNotEquals(driver.findElement(By.id("android:id/content")) .findElement(MobileBy .AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null); - assertNotEquals(driver.findElementById("android:id/content") + assertNotEquals(driver.findElement(By.id("android:id/content")) .findElements(MobileBy .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0); - assertNotEquals(driver.findElementById("android:id/content") + assertNotEquals(driver.findElement(By.id("android:id/content")) .findElements(MobileBy .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1); } @@ -59,7 +59,7 @@ public class AndroidElementTest extends BaseAndroidTest { Activity activity = new Activity("io.appium.android.apis", ".view.Controls1"); driver.startActivity(activity); AndroidElement editElement = driver - .findElementByAndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"); + .findElement(MobileBy.AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")")); editElement.sendKeys(originalValue); assertEquals(originalValue, editElement.getText()); String replacedValue = "replaced value"; @@ -68,7 +68,7 @@ public class AndroidElementTest extends BaseAndroidTest { } @Test public void scrollingToSubElement() { - driver.findElementByAccessibilityId("Views").click(); + driver.findElement(MobileBy.AccessibilityId("Views")).click(); AndroidElement list = driver.findElement(By.id("android:id/list")); MobileElement radioGroup = list .findElement(MobileBy @@ -83,7 +83,7 @@ public class AndroidElementTest extends BaseAndroidTest { Activity activity = new Activity("io.appium.android.apis", ".view.Controls1"); driver.startActivity(activity); AndroidElement editElement = driver - .findElementByAndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"); + .findElement(MobileBy.AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")")); editElement.setValue(value); assertEquals(value, editElement.getText()); } diff --git a/src/test/java/io/appium/java_client/android/AndroidOptionsTest.java b/src/test/java/io/appium/java_client/android/AndroidOptionsTest.java index 6b2d5d211..26061993f 100644 --- a/src/test/java/io/appium/java_client/android/AndroidOptionsTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidOptionsTest.java @@ -20,6 +20,7 @@ import io.appium.java_client.remote.MobilePlatform; import org.junit.Test; import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.Platform; import org.openqa.selenium.ScreenOrientation; import java.net.MalformedURLException; @@ -29,11 +30,10 @@ import static org.junit.Assert.assertEquals; public class AndroidOptionsTest { - private AndroidOptions androidOptions = new AndroidOptions(); @Test public void setsPlatformNameByDefault() { - assertEquals(MobilePlatform.ANDROID, androidOptions.getPlatformName()); + assertEquals(Platform.ANDROID, new AndroidOptions().getPlatformName()); } @Test @@ -43,7 +43,7 @@ public void acceptsExistingCapabilities() { capabilities.setCapability("platformVersion", "10"); capabilities.setCapability("newCommandTimeout", 60); - androidOptions = new AndroidOptions(capabilities); + AndroidOptions androidOptions = new AndroidOptions(capabilities); assertEquals("Pixel", androidOptions.getDeviceName()); assertEquals("10", androidOptions.getPlatformVersion()); @@ -52,6 +52,7 @@ public void acceptsExistingCapabilities() { @Test public void acceptsMobileCapabilities() throws MalformedURLException { + AndroidOptions androidOptions = new AndroidOptions(); androidOptions.setApp(new URL("http://example.com/myapp.apk")) .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2) .setPlatformVersion("10") diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java index 84f4b88b2..4564899f4 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java @@ -24,7 +24,7 @@ import io.appium.java_client.MobileElement; import org.junit.Before; import org.junit.Test; - +import org.openqa.selenium.By; public class AndroidSearchingTest extends BaseAndroidTest { @@ -52,17 +52,17 @@ public void setup() { } @Test public void findByXPathTest() { - String byXPath = "//android.widget.TextView[contains(@text, 'Animat')]"; - assertNotNull(driver.findElementByXPath(byXPath).getText()); - assertEquals(driver.findElementsByXPath(byXPath).size(), 1); + By byXPath = By.xpath("//android.widget.TextView[contains(@text, 'Animat')]"); + assertNotNull(driver.findElement(byXPath).getText()); + assertEquals(driver.findElements(byXPath).size(), 1); } @Test public void findScrollable() { - driver.findElementByAccessibilityId("Views").click(); + driver.findElement(MobileBy.AccessibilityId("Views")).click(); MobileElement radioGroup = driver - .findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()" + .findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()" + ".resourceId(\"android:id/list\")).scrollIntoView(" - + "new UiSelector().text(\"Radio Group\"));"); + + "new UiSelector().text(\"Radio Group\"));")); assertNotNull(radioGroup.getLocation()); } } diff --git a/src/test/java/io/appium/java_client/android/AndroidTouchTest.java b/src/test/java/io/appium/java_client/android/AndroidTouchTest.java index 1c375bae9..341b8d40b 100644 --- a/src/test/java/io/appium/java_client/android/AndroidTouchTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidTouchTest.java @@ -9,9 +9,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; import io.appium.java_client.MultiTouchAction; import io.appium.java_client.TouchAction; + import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; @@ -108,39 +110,35 @@ public void setUp() { @Test public void pressByCoordinatesTest() { Activity activity = new Activity("io.appium.android.apis", ".view.Buttons1"); driver.startActivity(activity); - Point point = - driver.findElementById("io.appium.android.apis:id/button_toggle").getLocation(); + Point point = driver.findElement(By.id("io.appium.android.apis:id/button_toggle")).getLocation(); new TouchAction(driver) .press(point(point.x + 20, point.y + 30)) .waitAction(waitOptions(ofSeconds(1))) .release() .perform(); - assertEquals("ON" ,driver - .findElementById("io.appium.android.apis:id/button_toggle").getText()); + assertEquals("ON", driver.findElement(By.id("io.appium.android.apis:id/button_toggle")).getText()); } @Test public void pressByElementTest() { Activity activity = new Activity("io.appium.android.apis", ".view.Buttons1"); driver.startActivity(activity); new TouchAction(driver) - .press(element(driver.findElementById("io.appium.android.apis:id/button_toggle"))) + .press(element(driver.findElement(By.id("io.appium.android.apis:id/button_toggle")))) .waitAction(waitOptions(ofSeconds(1))) .release() .perform(); - assertEquals("ON" ,driver - .findElementById("io.appium.android.apis:id/button_toggle").getText()); + assertEquals("ON", driver.findElement(By.id("io.appium.android.apis:id/button_toggle")).getText()); } @Test public void tapActionTestByElement() throws Exception { Activity activity = new Activity("io.appium.android.apis", ".view.ChronometerDemo"); driver.startActivity(activity); - AndroidElement chronometer = - driver.findElementById("io.appium.android.apis:id/chronometer"); + AndroidElement chronometer = driver.findElement(By.id("io.appium.android.apis:id/chronometer")); TouchAction startStop = new TouchAction(driver) - .tap(tapOptions().withElement(element(driver.findElementById("io.appium.android.apis:id/start")))) + .tap(tapOptions().withElement(element(driver.findElement(By.id("io.appium.android.apis:id/start"))))) .waitAction(waitOptions(ofSeconds(2))) - .tap(tapOptions().withElement(element(driver.findElementById("io.appium.android.apis:id/stop")))); + .tap(tapOptions().withElement(element(driver.findElement(By.id("io.appium.android.apis:id/stop"))))); startStop.perform(); @@ -153,14 +151,13 @@ public void setUp() { @Test public void tapActionTestByCoordinates() throws Exception { Activity activity = new Activity("io.appium.android.apis", ".view.ChronometerDemo"); driver.startActivity(activity); - AndroidElement chronometer = - driver.findElementById("io.appium.android.apis:id/chronometer"); + AndroidElement chronometer = driver.findElement(By.id("io.appium.android.apis:id/chronometer")); - Point center1 = driver.findElementById("io.appium.android.apis:id/start").getCenter(); + Point center1 = driver.findElement(By.id("io.appium.android.apis:id/start")).getCenter(); TouchAction startStop = new TouchAction(driver) .tap(point(center1.x, center1.y)) - .tap(element(driver.findElementById("io.appium.android.apis:id/stop"), 5, 5)); + .tap(element(driver.findElement(By.id("io.appium.android.apis:id/stop")), 5, 5)); startStop.perform(); String time = chronometer.getText(); @@ -173,9 +170,8 @@ public void setUp() { Activity activity = new Activity("io.appium.android.apis", ".view.Gallery1"); driver.startActivity(activity); - AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery"); - List images = gallery - .findElementsByClassName("android.widget.ImageView"); + AndroidElement gallery = driver.findElement(By.id("io.appium.android.apis:id/gallery")); + List images = gallery.findElements(MobileBy.className("android.widget.ImageView")); int originalImageCount = images.size(); Point location = gallery.getLocation(); Point center = gallery.getCenter(); @@ -186,22 +182,21 @@ public void setUp() { .moveTo(element(gallery,10,center.y - location.y)) .release(); swipe.perform(); - assertNotEquals(originalImageCount, gallery - .findElementsByClassName("android.widget.ImageView").size()); + assertNotEquals(originalImageCount, + gallery.findElements(MobileBy.className("android.widget.ImageView")).size()); } @Test public void multiTouchTest() { Activity activity = new Activity("io.appium.android.apis", ".view.Buttons1"); driver.startActivity(activity); TouchAction press = new TouchAction(driver) - .press(element(driver.findElementById("io.appium.android.apis:id/button_toggle"))) + .press(element(driver.findElement(By.id("io.appium.android.apis:id/button_toggle")))) .waitAction(waitOptions(ofSeconds(1))) .release(); new MultiTouchAction(driver) .add(press) .perform(); - assertEquals("ON" ,driver - .findElementById("io.appium.android.apis:id/button_toggle").getText()); + assertEquals("ON", driver.findElement(By.id("io.appium.android.apis:id/button_toggle")).getText()); } } diff --git a/src/test/java/io/appium/java_client/android/FingerPrintTest.java b/src/test/java/io/appium/java_client/android/FingerPrintTest.java index 712c384f8..02cf7dba4 100644 --- a/src/test/java/io/appium/java_client/android/FingerPrintTest.java +++ b/src/test/java/io/appium/java_client/android/FingerPrintTest.java @@ -18,7 +18,6 @@ import static io.appium.java_client.MobileBy.AndroidUIAutomator; import static java.util.concurrent.TimeUnit.SECONDS; -import static org.openqa.selenium.By.id; import io.appium.java_client.remote.MobileCapabilityType; import io.appium.java_client.service.local.AppiumDriverLocalService; @@ -28,6 +27,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.remote.DesiredCapabilities; @@ -66,27 +66,26 @@ private static void initDriver() { } private AndroidElement findElementByText(String text) { - return driver.findElements(id("android:id/title")).stream().filter(androidElement -> + return driver.findElements(By.id("android:id/title")).stream().filter(androidElement -> text.equals(androidElement.getText())).findFirst() .orElseThrow(() -> new NoSuchElementException(String.format("There is no element with the text '%s'", text))); } private void clickNext() { - driver.findElementById("com.android.settings:id/next_button").click(); + driver.findElement(By.id("com.android.settings:id/next_button")).click(); } private void clickFingerPrintNext() { - driver.findElementById("com.android.settings:id/fingerprint_next_button").click(); + driver.findElement(By.id("com.android.settings:id/fingerprint_next_button")).click(); } private void clickOKInPopup() { - driver.findElementById("android:id/button1").click(); + driver.findElement(By.id("android:id/button1")).click(); } private void enterPasswordAndContinue() { - driver.findElementById("com.android.settings:id/password_entry") - .sendKeys("1234\n"); + driver.findElement(By.id("com.android.settings:id/password_entry")).sendKeys("1234\n"); } private void clickOnSecurity() { diff --git a/src/test/java/io/appium/java_client/android/IntentTest.java b/src/test/java/io/appium/java_client/android/IntentTest.java index d2fde8e25..ed82dee0c 100644 --- a/src/test/java/io/appium/java_client/android/IntentTest.java +++ b/src/test/java/io/appium/java_client/android/IntentTest.java @@ -9,6 +9,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import java.util.function.Predicate; @@ -69,7 +70,7 @@ public class IntentTest { .setIntentFlags("0x4000000") .setOptionalIntentArguments("--es \"USERNAME\" \"AppiumIntentTest\" -t \"text/plain\""); driver.startActivity(activity); - assertEquals(driver.findElementById("com.prgguru.android:id/textView1").getText(), + assertEquals(driver.findElement(By.id("com.prgguru.android:id/textView1")).getText(), "Welcome AppiumIntentTest"); } } diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java index 19df3618a..8b18bcce6 100644 --- a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java +++ b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java @@ -24,7 +24,7 @@ public void afterMethod() { @Test public void testLandscapeRightRotation() { new WebDriverWait(driver, 20).until(ExpectedConditions - .elementToBeClickable(driver.findElementById("android:id/content") + .elementToBeClickable(driver.findElement(By.id("android:id/content")) .findElement(MobileBy.AccessibilityId("Graphics")))); DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 90); driver.rotate(landscapeRightRotation); @@ -34,7 +34,7 @@ public void testLandscapeRightRotation() { @Test public void testLandscapeLeftRotation() { new WebDriverWait(driver, 20).until(ExpectedConditions - .elementToBeClickable(driver.findElementById("android:id/content") + .elementToBeClickable(driver.findElement(By.id("android:id/content")) .findElement(MobileBy.AccessibilityId("Graphics")))); DeviceRotation landscapeLeftRotation = new DeviceRotation(0, 0, 270); driver.rotate(landscapeLeftRotation); @@ -44,7 +44,7 @@ public void testLandscapeLeftRotation() { @Test public void testPortraitUpsideDown() { new WebDriverWait(driver, 20).until(ExpectedConditions - .elementToBeClickable(driver.findElementById("android:id/content") + .elementToBeClickable(driver.findElement(By.id("android:id/content")) .findElement(MobileBy.AccessibilityId("Graphics")))); DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 180); driver.rotate(landscapeRightRotation); diff --git a/src/test/java/io/appium/java_client/appium/AndroidTest.java b/src/test/java/io/appium/java_client/appium/AndroidTest.java index aa3d2929e..47e2475e4 100644 --- a/src/test/java/io/appium/java_client/appium/AndroidTest.java +++ b/src/test/java/io/appium/java_client/appium/AndroidTest.java @@ -83,8 +83,8 @@ public Response execute(String driverCommand) { @Test public void findByAccessibilityIdFromDriverTest() { - assertNotEquals(driver.findElementByAccessibilityId("Graphics").getText(), null); - assertEquals(driver.findElementsByAccessibilityId("Graphics").size(), 1); + assertNotEquals(driver.findElement(MobileBy.AccessibilityId("Graphics")).getText(), null); + assertEquals(driver.findElements(MobileBy.AccessibilityId("Graphics")).size(), 1); } @Test public void findByAndroidUIAutomatorFromDriverTest() { @@ -100,20 +100,20 @@ public void findByAccessibilityIdFromDriverTest() { } @Test public void findByAccessibilityIdFromElementTest() { - assertNotEquals(driver.findElementById("android:id/content") + assertNotEquals(driver.findElement(By.id("android:id/content")) .findElement(MobileBy.AccessibilityId("Graphics")).getText(), null); - assertEquals(driver.findElementById("android:id/content") + assertEquals(driver.findElement(By.id("android:id/content")) .findElements(MobileBy.AccessibilityId("Graphics")).size(), 1); } @Test public void findByAndroidUIAutomatorFromElementTest() { - assertNotEquals(driver.findElementById("android:id/content") + assertNotEquals(driver.findElement(By.id("android:id/content")) .findElement(MobileBy .AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null); - assertNotEquals(driver.findElementById("android:id/content") + assertNotEquals(driver.findElement(By.id("android:id/content")) .findElements(MobileBy .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0); - assertNotEquals(driver.findElementById("android:id/content") + assertNotEquals(driver.findElement(By.id("android:id/content")) .findElements(MobileBy .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1); } @@ -134,7 +134,7 @@ public void findByAccessibilityIdFromDriverTest() { } @Test public void scrollingToSubElement() { - driver.findElementByAccessibilityId("Views").click(); + driver.findElement(MobileBy.AccessibilityId("Views")).click(); AndroidElement list = driver.findElement(By.id("android:id/list")); MobileElement radioGroup = list .findElement(MobileBy diff --git a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java index 3115f8997..3d1bb0f48 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java @@ -1,6 +1,5 @@ package io.appium.java_client.appium.element.generation.ios; -import static io.appium.java_client.MobileBy.AccessibilityId; import static io.appium.java_client.TestResources.testAppZip; import static io.appium.java_client.TestResources.vodQaAppZip; import static org.junit.Assert.assertTrue; @@ -9,6 +8,7 @@ import static org.openqa.selenium.By.partialLinkText; import io.appium.java_client.AppiumDriver; +import io.appium.java_client.MobileBy; import io.appium.java_client.appium.element.generation.BaseElementGenerationTest; import io.appium.java_client.ios.BaseIOSTest; import io.appium.java_client.ios.IOSElement; @@ -78,7 +78,7 @@ public void whenIOSNativeAppIsLaunched() { Capabilities caps = commonAppCapabilitiesSupplier.get(); return caps.merge(appFileSupplierFunction.apply(testApp).get()); }, commonPredicate, - AccessibilityId("Answer") + MobileBy.AccessibilityId("Answer") )); } @@ -92,10 +92,10 @@ public void whenIOSHybridAppIsLaunched() { new WebDriverWait(driver, 30) .until(ExpectedConditions.presenceOfElementLocated(id("login"))) .click(); - driver.findElementByAccessibilityId("webView").click(); + driver.findElement(MobileBy.AccessibilityId("webView")).click(); new WebDriverWait(driver, 30) .until(ExpectedConditions - .presenceOfElementLocated(AccessibilityId("Webview"))); + .presenceOfElementLocated(MobileBy.AccessibilityId("Webview"))); try { Thread.sleep(10000); } catch (InterruptedException e) { diff --git a/src/test/java/io/appium/java_client/events/AbilityToDefineListenersExternally.java b/src/test/java/io/appium/java_client/events/AbilityToDefineListenersExternally.java index 7357cc39b..91fceed10 100644 --- a/src/test/java/io/appium/java_client/events/AbilityToDefineListenersExternally.java +++ b/src/test/java/io/appium/java_client/events/AbilityToDefineListenersExternally.java @@ -3,6 +3,11 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + import io.appium.java_client.events.listeners.AlertListener2; import io.appium.java_client.events.listeners.ContextListener2; import io.appium.java_client.events.listeners.ElementListener2; @@ -12,9 +17,8 @@ import io.appium.java_client.events.listeners.RotationListener2; import io.appium.java_client.events.listeners.SearchingListener2; import io.appium.java_client.events.listeners.WindowListener2; -import org.junit.BeforeClass; -import org.junit.Test; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class AbilityToDefineListenersExternally extends BaseListenerTest { private static final String PREFIX = "Externally defined listener: "; @@ -42,14 +46,6 @@ public void searchContextEventTest() { is(true)); } - @Test - public void searchContextEventTest2() { - assertThat( - super - .assertThatSearchListenerWorksAgainstElements(emptyWebDriver, searchingListener, PREFIX), - is(true)); - } - @Test public void navigationEventTest() throws Exception { assertThat( diff --git a/src/test/java/io/appium/java_client/events/BaseListenerTest.java b/src/test/java/io/appium/java_client/events/BaseListenerTest.java index 6d8ef0170..5ce04f204 100644 --- a/src/test/java/io/appium/java_client/events/BaseListenerTest.java +++ b/src/test/java/io/appium/java_client/events/BaseListenerTest.java @@ -3,8 +3,8 @@ import static org.hamcrest.Matchers.contains; import static org.junit.Assert.assertThat; -import io.appium.java_client.MobileBy; -import io.appium.java_client.events.listeners.TestListener; +import java.net.URL; + import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; @@ -13,19 +13,21 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; -import java.net.URL; -import java.util.List; +import io.appium.java_client.MobileBy; +import io.appium.java_client.events.listeners.TestListener; public class BaseListenerTest { protected boolean assertThatSearchListenerWorks(EmptyWebDriver driver, TestListener listener, String prefix) { try { + listener.messages.clear(); + driver.findElement(By.id("someId")); assertThat(listener.messages, contains(prefix + "Attempt to find something using By.id: someId. The root element is null", prefix + "The searching for something using By.id: someId has beed finished. " - + "The root element was null")); + + "The root element was null")); driver.findElements(By.id("someId2")); @@ -37,67 +39,45 @@ protected boolean assertThatSearchListenerWorks(EmptyWebDriver driver, TestListe prefix + "The searching for something using By.id: someId2 has beed finished. " + "The root element was null")); - driver.findElement(By.id("someId")).findElement(By.className("someClazz")); + driver.findElement(By.id("someId")).findElement(MobileBy.className("someClazz")); assertThat(listener.messages, contains(prefix + "Attempt to find something using By.id: someId. The root element is null", - prefix + "The searching for something using By.id: someId has beed finished. " + prefix + "The searching for something using By.id: someId has beed finished. " + "The root element was null", - prefix + "Attempt to find something using By.id: someId2. The root element is null", - prefix + "The searching for something using By.id: someId2 has beed finished. " + prefix + "Attempt to find something using By.id: someId2. The root element is null", + prefix + "The searching for something using By.id: someId2 has beed finished. " + "The root element was null", - prefix + "Attempt to find something using By.id: someId. " + prefix + "Attempt to find something using By.id: someId. " + "The root element is null", - prefix + "The searching for something using By.id: someId has beed finished. " + prefix + "The searching for something using By.id: someId has beed finished. " + "The root element was null", prefix + "Attempt to find something using By.className: someClazz. " + "The root element is io.appium.java_client.events.StubWebElement", prefix + "The searching for something using By.className: someClazz has beed finished. " + "The root element was io.appium.java_client.events.StubWebElement")); - driver.findElements(By.id("someId2")).get(0).findElements(By.className("someClazz2")); + driver.findElements(By.id("someId2")).get(0).findElements(MobileBy.className("someClazz2")); assertThat(listener.messages, contains(prefix + "Attempt to find something using By.id: someId. The root element is null", - prefix + "The searching for something using By.id: someId has beed finished. " + prefix + "The searching for something using By.id: someId has beed finished. " + "The root element was null", - prefix + "Attempt to find something using By.id: someId2. The root element is null", - prefix + "The searching for something using By.id: someId2 has beed finished. " + prefix + "Attempt to find something using By.id: someId2. The root element is null", + prefix + "The searching for something using By.id: someId2 has beed finished. " + "The root element was null", - prefix + "Attempt to find something using By.id: someId. The root element is null", - prefix + "The searching for something using By.id: someId has beed finished. " + prefix + "Attempt to find something using By.id: someId. The root element is null", + prefix + "The searching for something using By.id: someId has beed finished. " + "The root element was null", - prefix + "Attempt to find something using By.className: someClazz. " + prefix + "Attempt to find something using By.className: someClazz. " + "The root element is io.appium.java_client.events.StubWebElement", - prefix + "The searching for something using By.className: someClazz has beed finished. " + prefix + "The searching for something using By.className: someClazz has beed finished. " + "The root element was io.appium.java_client.events.StubWebElement", - prefix + "Attempt to find something using By.id: someId2. The root element is null", - prefix + "The searching for something using By.id: someId2 has beed finished. " + prefix + "Attempt to find something using By.id: someId2. The root element is null", + prefix + "The searching for something using By.id: someId2 has beed finished. " + "The root element was null", - prefix + "Attempt to find something using By.className: someClazz2. " - + "The root element is io.appium.java_client.events.StubWebElement", - prefix + "The searching for something using By.className: someClazz2 has beed finished. " - + "The root element was io.appium.java_client.events.StubWebElement")); - return true; - } finally { - listener.messages.clear(); - } - } - - protected boolean assertThatSearchListenerWorksAgainstElements(EmptyWebDriver driver, TestListener listener, - String prefix) { - try { - List els = driver.findElementsByAccessibilityId("SomeAccessibility"); - StubWebElement e = driver.findElementByXPath("Some Path"); - - e.findElementByAccessibilityId("SomeAccessibility") - .findElement(MobileBy.AndroidUIAutomator("Android UI Automator")); - - assertThat(listener.messages, - contains(prefix + "Attempt to find something using By.AndroidUIAutomator: Android UI Automator. " + prefix + "Attempt to find something using By.className: someClazz2. " + "The root element is io.appium.java_client.events.StubWebElement", - prefix + "The searching for something using By.AndroidUIAutomator: " - + "Android UI Automator has " - + "beed finished. " + prefix + "The searching for something using By.className: someClazz2 has beed finished. " + "The root element was io.appium.java_client.events.StubWebElement")); return true; } finally { @@ -136,7 +116,9 @@ protected boolean assertThatNavigationListenerWorks(EmptyWebDriver driver, protected boolean assertThatElementListenerWorks(EmptyWebDriver driver, TestListener listener, String prefix) { try { - StubWebElement e = driver.findElementByXPath("Some Path"); + StubWebElement e = driver.findElement(MobileBy.AccessibilityId("SomeAccessibility")); + listener.messages.clear(); + e.click(); e.sendKeys("Test keys"); @@ -171,17 +153,21 @@ protected boolean assertThatJavaScriptListenerWorks(EmptyWebDriver driver, TestL protected boolean assertThatExceptionListenerWorks(EmptyWebDriver driver, TestListener listener, String prefix) { try { try { - driver.getPageSource(); + StubWebElement element = driver.findElement(MobileBy.AccessibilityId("SomeAccessibility")); + listener.messages.clear(); + + element.getRect(); } catch (Exception ignored) { ignored.printStackTrace(); } try { - driver.findElementByXPath("Some Path").getRect(); + driver.getPageSource(); } catch (Exception ignored) { ignored.printStackTrace(); } + assertThat(listener.messages, contains(prefix + "The exception was thrown: " + WebDriverException.class, diff --git a/src/test/java/io/appium/java_client/events/DefaultEventListenerTest.java b/src/test/java/io/appium/java_client/events/DefaultEventListenerTest.java index a2454edca..7cbdfee4f 100644 --- a/src/test/java/io/appium/java_client/events/DefaultEventListenerTest.java +++ b/src/test/java/io/appium/java_client/events/DefaultEventListenerTest.java @@ -5,6 +5,13 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import org.apache.commons.lang3.StringUtils; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.openqa.selenium.Capabilities; + import io.appium.java_client.events.listeners.AlertListener; import io.appium.java_client.events.listeners.ContextListener; import io.appium.java_client.events.listeners.ElementListener; @@ -15,12 +22,6 @@ import io.appium.java_client.events.listeners.SearchingListener; import io.appium.java_client.events.listeners.SingleListeners; import io.appium.java_client.events.listeners.WindowListener; -import org.apache.commons.lang3.StringUtils; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; -import org.openqa.selenium.Capabilities; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DefaultEventListenerTest extends BaseListenerTest { @@ -38,12 +39,6 @@ public void searchContextEventTest() { .listeners.get(SearchingListener.class), StringUtils.EMPTY), is(true)); } - @Test - public void searchContextEventTest2() { - assertThat(super.assertThatSearchListenerWorksAgainstElements(driver, SingleListeners - .listeners.get(SearchingListener.class), StringUtils.EMPTY), is(true)); - } - @Test public void navigationEventTest() throws Exception { assertThat(super.assertThatNavigationListenerWorks(driver, SingleListeners diff --git a/src/test/java/io/appium/java_client/events/EmptyWebDriver.java b/src/test/java/io/appium/java_client/events/EmptyWebDriver.java index 460c0b773..5bc7149c0 100644 --- a/src/test/java/io/appium/java_client/events/EmptyWebDriver.java +++ b/src/test/java/io/appium/java_client/events/EmptyWebDriver.java @@ -2,10 +2,6 @@ import com.google.common.collect.ImmutableList; -import io.appium.java_client.FindsByAccessibilityId; -import io.appium.java_client.FindsByAndroidUIAutomator; -import io.appium.java_client.FindsByFluentSelector; - import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.Alert; import org.openqa.selenium.By; @@ -15,7 +11,6 @@ import org.openqa.selenium.DeviceRotation; import org.openqa.selenium.HasCapabilities; import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.OutputType; import org.openqa.selenium.Rotatable; import org.openqa.selenium.ScreenOrientation; @@ -23,12 +18,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; -import org.openqa.selenium.internal.FindsByClassName; -import org.openqa.selenium.internal.FindsByCssSelector; -import org.openqa.selenium.internal.FindsById; -import org.openqa.selenium.internal.FindsByLinkText; -import org.openqa.selenium.internal.FindsByTagName; -import org.openqa.selenium.internal.FindsByXPath; +import org.openqa.selenium.WindowType; import org.openqa.selenium.logging.Logs; import org.openqa.selenium.remote.DesiredCapabilities; @@ -38,10 +28,8 @@ import java.util.Map; import java.util.Set; -public class EmptyWebDriver implements WebDriver, ContextAware, Rotatable, FindsByClassName, - FindsByCssSelector, FindsById, FindsByLinkText, FindsByTagName, FindsByXPath, - FindsByAccessibilityId, FindsByAndroidUIAutomator, - JavascriptExecutor, HasCapabilities, FindsByFluentSelector, TakesScreenshot { +public class EmptyWebDriver implements WebDriver, ContextAware, Rotatable, JavascriptExecutor, HasCapabilities, + TakesScreenshot { private static List createStubList() { return ImmutableList.of(new StubWebElement(), new StubWebElement()); @@ -91,20 +79,10 @@ private static List createStubList() { return new StubWebElement(); } - @Override - public StubWebElement findElement(String by, String using) throws WebDriverException, NoSuchElementException { - return new StubWebElement(); - } - @Override public List findElements(By by) { return createStubList(); } - @Override - public List findElements(String by, String using) throws WebDriverException { - return createStubList(); - } - @Override public String getPageSource() { throw new WebDriverException(); } @@ -137,78 +115,6 @@ public List findElements(String by, String using) throws WebDriv return new StubOptions(); } - @Override public StubWebElement findElementByClassName(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByClassName(String using) { - return createStubList(); - } - - @Override public StubWebElement findElementByCssSelector(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByCssSelector(String using) { - return createStubList(); - } - - @Override public StubWebElement findElementById(String using) { - return new StubWebElement(); - } - - @Override public List findElementsById(String using) { - return createStubList(); - } - - @Override public StubWebElement findElementByLinkText(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByLinkText(String using) { - return createStubList(); - } - - @Override public StubWebElement findElementByPartialLinkText(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByPartialLinkText(String using) { - return createStubList(); - } - - @Override public StubWebElement findElementByTagName(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByTagName(String using) { - return createStubList(); - } - - @Override public StubWebElement findElementByXPath(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByXPath(String using) { - return createStubList(); - } - - @Override public StubWebElement findElementByAccessibilityId(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByAccessibilityId(String using) { - return createStubList(); - } - - @Override public StubWebElement findElementByAndroidUIAutomator(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByAndroidUIAutomator(String using) { - return createStubList(); - } - @Override public Object executeScript(String script, Object... args) { return null; } @@ -257,6 +163,11 @@ private class StubTargetLocator implements TargetLocator { return driver; } + @Override + public WebDriver newWindow(WindowType typeHint) { + return driver; + } + @Override public WebDriver defaultContent() { return driver; } diff --git a/src/test/java/io/appium/java_client/events/ExtendedEventListenerTest.java b/src/test/java/io/appium/java_client/events/ExtendedEventListenerTest.java index 1ea04de2d..560875eb4 100644 --- a/src/test/java/io/appium/java_client/events/ExtendedEventListenerTest.java +++ b/src/test/java/io/appium/java_client/events/ExtendedEventListenerTest.java @@ -22,9 +22,9 @@ public class ExtendedEventListenerTest { @Test public void searchingTest() { StubWebElement androidElement = stubWebDriver.findElement(By.id("someId")); - androidElement.findElement("-some-criteria", "some value") + androidElement.findElement(MobileBy.custom("some value")) .findElements(MobileBy.AndroidUIAutomator("Android UI Automator")); - androidElement.findElements("-some-criteria2", "some value2").get(0) + androidElement.findElements(MobileBy.custom("some value2")).get(0) .findElements(MobileBy.AndroidUIAutomator("Android UI Automator2")); SearchingListener listener = (SearchingListener) SingleListeners diff --git a/src/test/java/io/appium/java_client/events/FewInstancesTest.java b/src/test/java/io/appium/java_client/events/FewInstancesTest.java index 4b5f7dcf9..b195cc0ba 100644 --- a/src/test/java/io/appium/java_client/events/FewInstancesTest.java +++ b/src/test/java/io/appium/java_client/events/FewInstancesTest.java @@ -4,6 +4,11 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThat; +import org.apache.commons.lang3.StringUtils; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openqa.selenium.WebDriver; + import io.appium.java_client.events.listeners.AlertListener; import io.appium.java_client.events.listeners.ContextListener; import io.appium.java_client.events.listeners.ElementListener; @@ -14,10 +19,6 @@ import io.appium.java_client.events.listeners.SearchingListener; import io.appium.java_client.events.listeners.SingleListeners; import io.appium.java_client.events.listeners.WindowListener; -import org.apache.commons.lang3.StringUtils; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openqa.selenium.WebDriver; public class FewInstancesTest extends BaseListenerTest { @@ -110,15 +111,6 @@ public void assertThatOneDriverDoNotListensToAnother() { searchingListener2.messages.size(), is(0)); } - @Test - public void assertThatOneDriverDoNotListensToAnother2() { - assertThat(super.assertThatSearchListenerWorksAgainstElements(emptyWebDriver1, - searchingListener1, StringUtils.EMPTY), - is(true)); - assertThat("The second searching listener should have no messages", - searchingListener2.messages.size(), is(0)); - } - @Test public void assertThatOneDriverDoNotListensToAnother3() throws Exception { assertThat(super.assertThatNavigationListenerWorks(emptyWebDriver1, diff --git a/src/test/java/io/appium/java_client/events/StubWebElement.java b/src/test/java/io/appium/java_client/events/StubWebElement.java index 36179206d..0e9c2a5d6 100644 --- a/src/test/java/io/appium/java_client/events/StubWebElement.java +++ b/src/test/java/io/appium/java_client/events/StubWebElement.java @@ -2,108 +2,23 @@ import com.google.common.collect.ImmutableList; -import io.appium.java_client.FindsByAccessibilityId; -import io.appium.java_client.FindsByAndroidUIAutomator; -import io.appium.java_client.FindsByFluentSelector; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; -import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.OutputType; import org.openqa.selenium.Point; import org.openqa.selenium.Rectangle; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; -import org.openqa.selenium.internal.FindsByClassName; -import org.openqa.selenium.internal.FindsByCssSelector; -import org.openqa.selenium.internal.FindsById; -import org.openqa.selenium.internal.FindsByLinkText; -import org.openqa.selenium.internal.FindsByTagName; -import org.openqa.selenium.internal.FindsByXPath; import java.util.ArrayList; import java.util.List; -public class StubWebElement implements WebElement, FindsByClassName, FindsByCssSelector, FindsById, - FindsByLinkText, FindsByTagName, FindsByXPath, FindsByAccessibilityId, - FindsByAndroidUIAutomator, FindsByFluentSelector { +public class StubWebElement implements WebElement { private static List createStubSubElementList() { return new ArrayList<>(ImmutableList.of(new StubWebElement(), new StubWebElement())); } - - @Override public WebElement findElementByAccessibilityId(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByAccessibilityId(String using) { - return createStubSubElementList(); - } - - @Override public WebElement findElementByAndroidUIAutomator(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByAndroidUIAutomator(String using) { - return createStubSubElementList(); - } - - @Override public WebElement findElementByClassName(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByClassName(String using) { - return createStubSubElementList(); - } - - @Override public WebElement findElementByCssSelector(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByCssSelector(String using) { - return createStubSubElementList(); - } - - @Override public WebElement findElementById(String using) { - return new StubWebElement(); - } - - @Override public List findElementsById(String using) { - return createStubSubElementList(); - } - - @Override public WebElement findElementByLinkText(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByLinkText(String using) { - return createStubSubElementList(); - } - - @Override public WebElement findElementByPartialLinkText(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByPartialLinkText(String using) { - return createStubSubElementList(); - } - - @Override public WebElement findElementByTagName(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByTagName(String using) { - return createStubSubElementList(); - } - - @Override public WebElement findElementByXPath(String using) { - return new StubWebElement(); - } - - @Override public List findElementsByXPath(String using) { - return createStubSubElementList(); - } - @Override public void click() { //There is no clicking. It is STUB. } @@ -144,20 +59,10 @@ private static List createStubSubElementList() { return createStubSubElementList(); } - @Override - public List findElements(String by, String using) throws WebDriverException { - return createStubSubElementList(); - } - @Override public WebElement findElement(By by) { return new StubWebElement(); } - @Override - public WebElement findElement(String by, String using) throws WebDriverException, NoSuchElementException { - return new StubWebElement(); - } - @Override public boolean isDisplayed() { return false; } diff --git a/src/test/java/io/appium/java_client/events/StubWindow.java b/src/test/java/io/appium/java_client/events/StubWindow.java index 066f2d08f..21d6580f4 100644 --- a/src/test/java/io/appium/java_client/events/StubWindow.java +++ b/src/test/java/io/appium/java_client/events/StubWindow.java @@ -25,6 +25,11 @@ public class StubWindow implements WebDriver.Window { //STUB it does nothing } + @Override + public void minimize() { + //STUB it does nothing + } + @Override public void fullscreen() { //STUB it does nothing } diff --git a/src/test/java/io/appium/java_client/events/WebDriverEventListenerCompatibilityTest.java b/src/test/java/io/appium/java_client/events/WebDriverEventListenerCompatibilityTest.java index 0380b7a59..aa6fd3656 100644 --- a/src/test/java/io/appium/java_client/events/WebDriverEventListenerCompatibilityTest.java +++ b/src/test/java/io/appium/java_client/events/WebDriverEventListenerCompatibilityTest.java @@ -8,14 +8,15 @@ import static org.openqa.selenium.By.xpath; import static org.openqa.selenium.OutputType.BASE64; -import io.appium.java_client.events.listeners.AppiumListener; -import io.appium.java_client.events.listeners.SingleListeners; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import org.openqa.selenium.Alert; +import io.appium.java_client.events.listeners.AppiumListener; +import io.appium.java_client.events.listeners.SingleListeners; + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class WebDriverEventListenerCompatibilityTest extends BaseListenerTest { @@ -35,12 +36,6 @@ public void searchContextEventTest() { is(true)); } - @Test - public void searchContextEventTest2() { - assertThat(super.assertThatSearchListenerWorksAgainstElements(driver, - listener, WEBDRIVER_EVENT_LISTENER), - is(true)); - } @Test public void navigationEventTest() throws Exception { diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index a1d7a0fb3..7ef1fad00 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -60,7 +60,7 @@ public void addCustomCommandWithSessionIdTest() { @Test public void addCustomCommandWithElementIdTest() { - IOSElement intA = driver.findElementById("IntegerA"); + IOSElement intA = driver.findElement(By.id("IntegerA")); intA.clear(); driver.addCommand(HttpMethod.POST, String.format("/session/%s/appium/element/%s/value", driver.getSessionId(), intA.getId()), "setNewValue"); @@ -79,7 +79,7 @@ public void getDeviceTimeTest() { } @Test public void hideKeyboardWithParametersTest() { - new WebDriverWait(driver, 30) + new WebDriverWait(driver, Duration.ofSeconds(30)) .until(ExpectedConditions.presenceOfElementLocated(By.id("IntegerA"))) .click(); driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done"); @@ -118,7 +118,7 @@ public void getDeviceTimeTest() { } @Test public void keyboardTest() { - MobileElement element = driver.findElementById("IntegerA"); + MobileElement element = driver.findElement(By.id("IntegerA")); element.click(); assertTrue(driver.isKeyboardShown()); } @@ -142,10 +142,10 @@ public void getDeviceTimeTest() { } @Test public void putAIntoBackgroundWithoutRestoreTest() { - waitUntilTrue(() -> !driver.findElementsById("IntegerA").isEmpty(), + waitUntilTrue(() -> !driver.findElements(By.id("IntegerA")).isEmpty(), Duration.ofSeconds(10), Duration.ofSeconds(1)); driver.runAppInBackground(Duration.ofSeconds(-1)); - waitUntilTrue(() -> driver.findElementsById("IntegerA").isEmpty(), + waitUntilTrue(() -> driver.findElements(By.id("IntegerA")).isEmpty(), Duration.ofSeconds(10), Duration.ofSeconds(1)); driver.activateApp(BUNDLE_ID); } diff --git a/src/test/java/io/appium/java_client/ios/IOSElementTest.java b/src/test/java/io/appium/java_client/ios/IOSElementTest.java index 4389d1888..582e9f97c 100644 --- a/src/test/java/io/appium/java_client/ios/IOSElementTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSElementTest.java @@ -12,13 +12,14 @@ import org.openqa.selenium.By; import org.openqa.selenium.support.ui.WebDriverWait; +import io.appium.java_client.MobileBy; + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class IOSElementTest extends AppIOSTest { @Test public void findByAccessibilityIdTest() { - assertThat(driver.findElementsByAccessibilityId("Compute Sum").size(), - not(is(0))); + assertThat(driver.findElements(MobileBy.AccessibilityId("Compute Sum")).size(), not(is(0))); } // FIXME: Stabilize the test on CI @@ -28,7 +29,7 @@ public void setValueTest() { WebDriverWait wait = new WebDriverWait(driver, 20); IOSElement slider = wait.until( - driver1 -> driver1.findElement(By.className("XCUIElementTypeSlider"))); + driver1 -> driver1.findElement(MobileBy.className("XCUIElementTypeSlider"))); slider.setValue("0%"); assertEquals("0%", slider.getAttribute("value")); } diff --git a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java index de8bcbb36..b48410348 100644 --- a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java @@ -2,7 +2,10 @@ import static org.junit.Assert.assertTrue; +import java.time.Duration; + import org.junit.Test; +import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; @@ -15,19 +18,19 @@ public class IOSNativeWebTapSettingTest extends BaseSafariTest { // do a click with nativeWebTap turned on, and assert we get to the right page driver.nativeWebTap(true); - WebElement el = driver.findElementById("i am a link"); + WebElement el = driver.findElement(By.id("i am a link")); el.click(); - assertTrue(new WebDriverWait(driver, 30) + assertTrue(new WebDriverWait(driver, Duration.ofSeconds(30)) .until(ExpectedConditions.titleIs("I am another page title - Sauce Labs"))); driver.navigate().back(); // now do a click with it turned off and assert the same behavior - assertTrue(new WebDriverWait(driver, 30) + assertTrue(new WebDriverWait(driver, Duration.ofSeconds(30)) .until(ExpectedConditions.titleIs("I am a page title - Sauce Labs"))); driver.nativeWebTap(false); - el = driver.findElementById("i am a link"); + el = driver.findElement(By.id("i am a link")); el.click(); - assertTrue(new WebDriverWait(driver, 30) + assertTrue(new WebDriverWait(driver, Duration.ofSeconds(30)) .until(ExpectedConditions.titleIs("I am another page title - Sauce Labs"))); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSOptionsTest.java b/src/test/java/io/appium/java_client/ios/IOSOptionsTest.java index 5fc1262e8..4bfa02ea6 100644 --- a/src/test/java/io/appium/java_client/ios/IOSOptionsTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSOptionsTest.java @@ -20,6 +20,7 @@ import io.appium.java_client.remote.MobilePlatform; import org.junit.Test; import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.Platform; import org.openqa.selenium.ScreenOrientation; import java.net.MalformedURLException; @@ -33,7 +34,7 @@ public class IOSOptionsTest { @Test public void setsPlatformNameByDefault() { - assertEquals(MobilePlatform.IOS, iosOptions.getPlatformName()); + assertEquals(Platform.IOS, iosOptions.getPlatformName()); } @Test diff --git a/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java b/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java index 82b1a122f..e8a0bbc16 100644 --- a/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java @@ -20,32 +20,34 @@ import org.junit.Test; +import io.appium.java_client.MobileBy; + public class IOSSearchingTest extends AppIOSTest { @Test public void findByAccessibilityIdTest() { assertNotEquals(driver - .findElementByAccessibilityId("ComputeSumButton") - .getText(), null); + .findElement(MobileBy.AccessibilityId("ComputeSumButton")) + .getText(), null); assertNotEquals(driver - .findElementsByAccessibilityId("ComputeSumButton") + .findElements(MobileBy.AccessibilityId("ComputeSumButton")) .size(), 0); } @Test public void findByByIosPredicatesTest() { assertNotEquals(driver - .findElementByIosNsPredicate("name like 'Answer'") + .findElement(MobileBy.iOSNsPredicateString("name like 'Answer'")) .getText(), null); assertNotEquals(driver - .findElementsByIosNsPredicate("name like 'Answer'") + .findElements(MobileBy.iOSNsPredicateString("name like 'Answer'")) .size(), 0); } @Test public void findByByIosClassChainTest() { assertNotEquals(driver - .findElementByIosClassChain("**/XCUIElementTypeButton") + .findElement(MobileBy.iOSClassChain("**/XCUIElementTypeButton")) .getText(), null); assertNotEquals(driver - .findElementsByIosClassChain("**/XCUIElementTypeButton") + .findElements(MobileBy.iOSClassChain("**/XCUIElementTypeButton")) .size(), 0); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java index 560fb2245..faf2ab98b 100644 --- a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java @@ -9,12 +9,13 @@ import static org.junit.Assert.assertNotNull; import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent; +import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; import io.appium.java_client.MultiTouchAction; -import io.appium.java_client.TouchAction; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; +import org.openqa.selenium.By; import org.openqa.selenium.support.ui.WebDriverWait; @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -22,28 +23,28 @@ public class IOSTouchTest extends AppIOSTest { @Test public void tapTest() { - IOSElement intA = driver.findElementById("IntegerA"); - IOSElement intB = driver.findElementById("IntegerB"); + IOSElement intA = driver.findElement(By.id("IntegerA")); + IOSElement intB = driver.findElement(By.id("IntegerB")); intA.clear(); intB.clear(); intA.sendKeys("2"); intB.sendKeys("4"); - MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); + MobileElement e = driver.findElement(MobileBy.AccessibilityId("ComputeSumButton")); new IOSTouchAction(driver).tap(tapOptions().withElement(element(e))).perform(); - assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6"); + assertEquals(driver.findElement(By.xpath("//*[@name = \"Answer\"]")).getText(), "6"); } @Test public void touchWithPressureTest() { - IOSElement intA = driver.findElementById("IntegerA"); - IOSElement intB = driver.findElementById("IntegerB"); + IOSElement intA = driver.findElement(By.id("IntegerA")); + IOSElement intB = driver.findElement(By.id("IntegerB")); intA.clear(); intB.clear(); intA.sendKeys("2"); intB.sendKeys("4"); - MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); + MobileElement e = driver.findElement(MobileBy.AccessibilityId("ComputeSumButton")); new IOSTouchAction(driver) .press(iosPressOptions() .withElement(element(e)) @@ -51,12 +52,12 @@ public void touchWithPressureTest() { .waitAction(waitOptions(ofMillis(100))) .release() .perform(); - assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6"); + assertEquals(driver.findElement(By.xpath("//*[@name = \"Answer\"]")).getText(), "6"); } @Test public void multiTouchTest() { - MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); - MobileElement e2 = driver.findElementByAccessibilityId("show alert"); + MobileElement e = driver.findElement(MobileBy.AccessibilityId("ComputeSumButton")); + MobileElement e2 = driver.findElement(MobileBy.AccessibilityId("show alert")); IOSTouchAction tap1 = new IOSTouchAction(driver).tap(tapOptions().withElement(element(e))); IOSTouchAction tap2 = new IOSTouchAction(driver).tap(tapOptions().withElement(element(e2))); @@ -69,12 +70,12 @@ public void touchWithPressureTest() { } @Test public void doubleTapTest() { - IOSElement firstField = driver.findElementById("IntegerA"); + IOSElement firstField = driver.findElement(By.id("IntegerA")); firstField.sendKeys("2"); IOSTouchAction iosTouchAction = new IOSTouchAction(driver); iosTouchAction.doubleTap(element(firstField)); - IOSElement editingMenu = driver.findElementByClassName("XCUIElementTypeTextField"); + IOSElement editingMenu = driver.findElement(MobileBy.className("XCUIElementTypeTextField")); assertNotNull(editingMenu); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java index 7c8f380c3..03b79b2b6 100644 --- a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java @@ -2,6 +2,8 @@ import static org.junit.Assert.assertTrue; +import java.time.Duration; + import io.appium.java_client.MobileBy; import org.junit.Test; import org.openqa.selenium.By; @@ -12,14 +14,14 @@ public class IOSWebViewTest extends BaseIOSWebViewTest { @Test public void webViewPageTestCase() throws InterruptedException { - new WebDriverWait(driver, 30) + new WebDriverWait(driver, Duration.ofSeconds(30)) .until(ExpectedConditions.presenceOfElementLocated(By.id("login"))) .click(); - driver.findElementByAccessibilityId("webView").click(); - new WebDriverWait(driver, 30) + driver.findElement(MobileBy.AccessibilityId("webView")).click(); + new WebDriverWait(driver, Duration.ofSeconds(30)) .until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("Webview"))); findAndSwitchToWebView(); - WebElement el = driver.findElementByPartialLinkText("login"); + WebElement el = driver.findElement(By.partialLinkText("login")); assertTrue(el.isDisplayed()); } }