From 9d8341684e6e6e8b22d724fc8fbc8b2a1d769bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Thu, 18 Jul 2024 10:29:03 +0200 Subject: [PATCH] Added webdriver config for Android and IOS --- .../tic/testframework/appium/Browsers.java | 5 + .../mobile/driver/AndroidConfig.java | 34 ++ .../mobile/driver/AppiumDriverFactory.java | 39 ++- .../mobile/driver/IOSConfig.java | 33 ++ .../mobile/driver/MobileOsChecker.java | 20 +- .../mobile/driver/SafariMobileConfig.java | 33 ++ .../webdrivermanager/AppiumDriverRequest.java | 10 +- .../test/apps/TesterraMobileApp2Test.java | 51 +++ .../test/guielement/MobileGuiElementTest.java | 291 ------------------ .../test/guielement/MobileUiElementTest.java | 20 +- appium/src/test/resources/test.properties | 4 +- 11 files changed, 231 insertions(+), 309 deletions(-) create mode 100644 appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/AndroidConfig.java create mode 100644 appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/IOSConfig.java create mode 100644 appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/SafariMobileConfig.java create mode 100644 appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/apps/TesterraMobileApp2Test.java delete mode 100644 appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/guielement/MobileGuiElementTest.java diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/appium/Browsers.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/appium/Browsers.java index 155d710b..3357f706 100644 --- a/appium/src/main/java/eu/tsystems/mms/tic/testframework/appium/Browsers.java +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/appium/Browsers.java @@ -28,6 +28,11 @@ public class Browsers { public static final String windows = "windows"; public static final String mobile_chrome = "mobile_chrome"; public static final String mobile_safari = "mobile_safari"; + + // Value for app tests + public static final String android = "android"; + public static final String ios = "ios"; + // Default value for AppiumDriverRequest public static final String mobile = "mobile"; } diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/AndroidConfig.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/AndroidConfig.java new file mode 100644 index 00000000..d6c51a78 --- /dev/null +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/AndroidConfig.java @@ -0,0 +1,34 @@ +/* + * Testerra + * + * (C) 2024, Martin Großmann, Deutsche Telekom MMS GmbH, Deutsche Telekom AG + * + * Deutsche Telekom AG and all other contributors / + * copyright owners license 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 eu.tsystems.mms.tic.testframework.mobile.driver; + +import eu.tsystems.mms.tic.testframework.useragents.UserAgentConfig; +import io.appium.java_client.android.options.UiAutomator2Options; +import io.appium.java_client.ios.options.XCUITestOptions; + +/** + * Created on 2024-07-18 + * + * @author mgn + */ +public interface AndroidConfig extends UserAgentConfig { +} diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/AppiumDriverFactory.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/AppiumDriverFactory.java index 6c5cbcff..4311d233 100644 --- a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/AppiumDriverFactory.java +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/AppiumDriverFactory.java @@ -33,6 +33,7 @@ import eu.tsystems.mms.tic.testframework.pageobjects.internal.core.GuiElementData; import eu.tsystems.mms.tic.testframework.report.model.context.SessionContext; import eu.tsystems.mms.tic.testframework.report.utils.IExecutionContextController; +import eu.tsystems.mms.tic.testframework.testing.WebDriverManagerProvider; import eu.tsystems.mms.tic.testframework.utils.AppiumProperties; import eu.tsystems.mms.tic.testframework.utils.TimerUtils; import eu.tsystems.mms.tic.testframework.webdriver.WebDriverFactory; @@ -48,11 +49,12 @@ import io.appium.java_client.ios.options.XCUITestOptions; import io.appium.java_client.remote.MobileBrowserType; import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.safari.options.SafariOptions; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.Capabilities; -import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.support.events.EventFiringDecorator; import org.testng.TestException; @@ -69,7 +71,11 @@ * * @author Eric Kubenka */ -public class AppiumDriverFactory implements WebDriverFactory, Loggable, AppiumCapabilityHelper { +public class AppiumDriverFactory implements + WebDriverFactory, + Loggable, + AppiumCapabilityHelper, + WebDriverManagerProvider { @Override public WebDriverRequest prepareWebDriverRequest(WebDriverRequest webDriverRequest) { @@ -83,9 +89,6 @@ public WebDriverRequest prepareWebDriverRequest(WebDriverRequest webDriverReques finalRequest.setBrowser(webDriverRequest.getBrowser()); } - MutableCapabilities requestCapabilities = finalRequest.getMutableCapabilities(); - IExecutionContextController executionContext = Testerra.getInjector().getInstance(IExecutionContextController.class); - Platform platform = new MobileOsChecker().getPlatform(webDriverRequest); Capabilities userAgentCapabilities = null; @@ -96,7 +99,15 @@ public WebDriverRequest prepareWebDriverRequest(WebDriverRequest webDriverReques UiAutomator2Options androidOptions = new UiAutomator2Options(); if (Browsers.mobile_chrome.equals(webDriverRequest.getBrowser())) { androidOptions.setCapability(CapabilityType.BROWSER_NAME, MobileBrowserType.CHROME); + ChromeOptions chromeOptions = new ChromeOptions(); + WEB_DRIVER_MANAGER.getUserAgentConfig(Browsers.mobile_chrome) + .ifPresent(userAgentConfig -> userAgentConfig.configure(chromeOptions)); + androidOptions = androidOptions.merge(chromeOptions); } + UiAutomator2Options customAndroidOptions = new UiAutomator2Options(); + WEB_DRIVER_MANAGER.getUserAgentConfig(Browsers.android) + .ifPresent(userAgentConfig -> userAgentConfig.configure(customAndroidOptions)); + androidOptions = androidOptions.merge(customAndroidOptions); userAgentCapabilities = androidOptions; break; } @@ -105,7 +116,16 @@ public WebDriverRequest prepareWebDriverRequest(WebDriverRequest webDriverReques XCUITestOptions iosOptions = new XCUITestOptions(); if (Browsers.mobile_safari.equals(webDriverRequest.getBrowser())) { iosOptions.setCapability(CapabilityType.BROWSER_NAME, MobileBrowserType.SAFARI); + SafariOptions safariOptions = new SafariOptions(); + + WEB_DRIVER_MANAGER.getUserAgentConfig(Browsers.mobile_safari) + .ifPresent(userAgentConfig -> userAgentConfig.configure(safariOptions)); + iosOptions = iosOptions.merge(safariOptions); } + XCUITestOptions customIosOptions = new XCUITestOptions(); + WEB_DRIVER_MANAGER.getUserAgentConfig(Browsers.ios) + .ifPresent(userAgentConfig -> userAgentConfig.configure(customIosOptions)); + iosOptions = iosOptions.merge(customIosOptions); userAgentCapabilities = iosOptions; break; } @@ -133,6 +153,7 @@ public WebDriverRequest prepareWebDriverRequest(WebDriverRequest webDriverReques } } + IExecutionContextController executionContext = Testerra.getInjector().getInstance(IExecutionContextController.class); otherOptions.setCapability(APPIUM_CAPABILITY_NAME_TEST_NAME, executionContext.getExecutionContext().getRunConfig().getReportName()); // TODO: Handle app capabilities from test.properties @@ -239,7 +260,13 @@ public WebDriver setupNewWebDriverSession(WebDriver webDriver, SessionContext se @Override public List getSupportedBrowsers() { - return Arrays.asList(Browsers.mobile_chrome, Browsers.mobile_safari, Browsers.mobile); + return Arrays.asList( + Browsers.mobile_chrome, + Browsers.mobile_safari, + Browsers.mobile, + Browsers.android, + Browsers.ios + ); } @Override diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/IOSConfig.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/IOSConfig.java new file mode 100644 index 00000000..f4bbd51b --- /dev/null +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/IOSConfig.java @@ -0,0 +1,33 @@ +/* + * Testerra + * + * (C) 2024, Martin Großmann, Deutsche Telekom MMS GmbH, Deutsche Telekom AG + * + * Deutsche Telekom AG and all other contributors / + * copyright owners license 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 eu.tsystems.mms.tic.testframework.mobile.driver; + +import eu.tsystems.mms.tic.testframework.useragents.UserAgentConfig; +import io.appium.java_client.ios.options.XCUITestOptions; + +/** + * Created on 2024-07-18 + * + * @author mgn + */ +public interface IOSConfig extends UserAgentConfig { +} diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/MobileOsChecker.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/MobileOsChecker.java index 6a89f352..d577e111 100644 --- a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/MobileOsChecker.java +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/MobileOsChecker.java @@ -61,15 +61,22 @@ public Platform getPlatform(WebDriver driver) { } } - // Returns true if WebDriverRequest contains typical app capabilities + /** + * Returns true if WebDriverRequest contains typical app capabilities. + * + * The method checks all possible caps and there values to find out the platform. + */ public boolean isAppTest(WebDriverRequest webDriverRequest, Platform platform) { Capabilities capabilities = webDriverRequest.getCapabilities(); MutableCapabilities mutableCapabilities = ((AbstractWebDriverRequest) webDriverRequest).getMutableCapabilities(); switch (platform) { case ANDROID: - // should be instance of UiAutomator2Options --> platform already set - return "Espresso".equalsIgnoreCase(getCap(capabilities, APPIUM_AUTOMATION_NAME)) + return capabilities.getPlatformName() == Platform.ANDROID // if instance of UiAutomator2Options --> platform already set + || mutableCapabilities.getPlatformName() == Platform.ANDROID + || webDriverRequest.getBrowser().equalsIgnoreCase(Browsers.android) + || capabilities.getBrowserName().equalsIgnoreCase(Browsers.android) + || "Espresso".equalsIgnoreCase(getCap(capabilities, APPIUM_AUTOMATION_NAME)) || "UiAutomator2".equalsIgnoreCase(getCap(capabilities, APPIUM_AUTOMATION_NAME)) || "UiAutomator".equalsIgnoreCase(getCap(capabilities, APPIUM_AUTOMATION_NAME)) || getCap(capabilities, APPIUM_APP_PACKAGE) != null @@ -80,8 +87,11 @@ public boolean isAppTest(WebDriverRequest webDriverRequest, Platform platform) { || getCap(mutableCapabilities, APPIUM_APP_PACKAGE) != null || getCap(mutableCapabilities, APPIUM_APP_ACTIVITY) != null; case IOS: - // should be instance of XCUITestOptions --> platform already set - return "XCUITest".equalsIgnoreCase(getCap(capabilities, APPIUM_AUTOMATION_NAME)) + return capabilities.getPlatformName() == Platform.IOS // if instance of XCUITestOptions --> platform already set + || mutableCapabilities.getPlatformName() == Platform.IOS + || webDriverRequest.getBrowser().equalsIgnoreCase(Browsers.ios) + || capabilities.getBrowserName().equalsIgnoreCase(Browsers.ios) + || "XCUITest".equalsIgnoreCase(getCap(capabilities, APPIUM_AUTOMATION_NAME)) || "UIAutomation".equalsIgnoreCase(getCap(capabilities, APPIUM_AUTOMATION_NAME)) || getCap(capabilities, APPIUM_BUNDLE_ID) != null || "XCUITest".equalsIgnoreCase(getCap(mutableCapabilities, APPIUM_AUTOMATION_NAME)) diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/SafariMobileConfig.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/SafariMobileConfig.java new file mode 100644 index 00000000..131c4245 --- /dev/null +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/SafariMobileConfig.java @@ -0,0 +1,33 @@ +/* + * Testerra + * + * (C) 2024, Martin Großmann, Deutsche Telekom MMS GmbH, Deutsche Telekom AG + * + * Deutsche Telekom AG and all other contributors / + * copyright owners license 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 eu.tsystems.mms.tic.testframework.mobile.driver; + +import eu.tsystems.mms.tic.testframework.useragents.UserAgentConfig; +import io.appium.java_client.safari.options.SafariOptions; + +/** + * Created on 2024-07-18 + * + * @author mgn + */ +public interface SafariMobileConfig extends UserAgentConfig { +} diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/AppiumDriverRequest.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/AppiumDriverRequest.java index db818709..ca6f75ee 100644 --- a/appium/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/AppiumDriverRequest.java +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/webdrivermanager/AppiumDriverRequest.java @@ -60,7 +60,7 @@ public void setDeviceQuery(String deviceQuery) { } public String getDeviceQuery() { - return this.getMutableCapabilities().getCapability(APPIUM_DEVICE_QUERY).toString(); + return (String) this.getMutableCapabilities().getCapability(APPIUM_DEVICE_QUERY); } public void setAccessKey(String accessKey) { @@ -72,7 +72,7 @@ public void setAppiumEngine(String engine) { } public String getAppiumEngine() { - return this.getMutableCapabilities().getCapability(getAppiumCap(APPIUM_AUTOMATION_NAME)).toString(); + return (String) this.getMutableCapabilities().getCapability(getAppiumCap(APPIUM_AUTOMATION_NAME)); } public void setDeviceName(String deviceName) { @@ -80,7 +80,7 @@ public void setDeviceName(String deviceName) { } public String getDeviceName() { - return this.getMutableCapabilities().getCapability(getAppiumCap(APPIUM_DEVICE_NAME)).toString(); + return (String) this.getMutableCapabilities().getCapability(getAppiumCap(APPIUM_DEVICE_NAME)); } public void setPlatformVersion(String platformVersion) { @@ -88,7 +88,7 @@ public void setPlatformVersion(String platformVersion) { } public String getPlatformVersion() { - return this.getMutableCapabilities().getCapability(getAppiumCap(APPIUM_PLATFORM_VERSION)).toString(); + return (String) this.getMutableCapabilities().getCapability(getAppiumCap(APPIUM_PLATFORM_VERSION)); } public void setDeviceId(String id) { @@ -96,6 +96,6 @@ public void setDeviceId(String id) { } public String getDeviceId() { - return this.getMutableCapabilities().getCapability(getAppiumCap(APPIUM_UDID)).toString(); + return (String) this.getMutableCapabilities().getCapability(getAppiumCap(APPIUM_UDID)); } } diff --git a/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/apps/TesterraMobileApp2Test.java b/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/apps/TesterraMobileApp2Test.java new file mode 100644 index 00000000..8bbba40f --- /dev/null +++ b/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/apps/TesterraMobileApp2Test.java @@ -0,0 +1,51 @@ +package eu.tsystems.mms.tic.testframework.mobile.test.apps; + +import eu.tsystems.mms.tic.testframework.appium.Browsers; +import eu.tsystems.mms.tic.testframework.mobile.driver.AndroidConfig; +import eu.tsystems.mms.tic.testframework.mobile.driver.IOSConfig; +import eu.tsystems.mms.tic.testframework.mobile.test.AbstractAppiumTest; +import eu.tsystems.mms.tic.testframework.utils.TimerUtils; +import eu.tsystems.mms.tic.testframework.utils.UITestUtils; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created on 2024-07-17 + * + * @author mgn + */ +public class TesterraMobileApp2Test extends AbstractAppiumTest { + + @BeforeClass + public void initCaps() { + WEB_DRIVER_MANAGER.setUserAgentConfig(Browsers.android, (AndroidConfig) options -> { + options.setApp("cloud:com.telekom.mms.cqa.mdc.androidapp/.HomeActivity"); + options.setAppPackage("com.telekom.mms.cqa.mdc.androidapp"); + options.setAppActivity(".HomeActivity"); + }); + + WEB_DRIVER_MANAGER.setUserAgentConfig(Browsers.ios, (IOSConfig) options -> { + options.setApp("cloud:com.telekom.mms.cqa.mdc.iosapp"); + options.setBundleId("com.telekom.mms.cqa.mdc.iosapp"); + }); + } + + /** + * This test opens the mobile app on iOS and Android. + *

+ * The platform specific caps are set by the method 'initCaps'. + * The property 'tt.browser' defines which platform should used for test: + * tt.browser=android or tt.browser=ios + *

+ * If a device query is needed, the properties 'tt.mobile.device.query.ios' and + * 'tt.mobile.device.query.android' are used to select a device from a cloud. + */ + @Test + public void testT01OpenApp() { + WebDriver webDriver = WEB_DRIVER_MANAGER.getWebDriver(); + TimerUtils.sleep(4000); + UITestUtils.takeScreenshots(); + } + +} diff --git a/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/guielement/MobileGuiElementTest.java b/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/guielement/MobileGuiElementTest.java deleted file mode 100644 index 55f3ac35..00000000 --- a/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/guielement/MobileGuiElementTest.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Testerra - * - * (C) 2020, Eric Kubenka, T-Systems Multimedia Solutions GmbH, Deutsche Telekom AG - * - * Deutsche Telekom AG and all other contributors / - * copyright owners license 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 eu.tsystems.mms.tic.testframework.mobile.test.guielement; - -import eu.tsystems.mms.tic.testframework.mobile.test.AbstractAppiumTest; -import eu.tsystems.mms.tic.testframework.pageobjects.GuiElement; -import eu.tsystems.mms.tic.testframework.pageobjects.Locate; -import eu.tsystems.mms.tic.testframework.webdrivermanager.WebDriverManager; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.List; - -/** - * Date: 16.09.2020 - * Time: 12:45 - * - * @author Eric Kubenka - */ -public class MobileGuiElementTest extends AbstractAppiumTest { - - @Test - public void testT01_isPresent() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/login"); - - final GuiElement inputUserName = new GuiElement(driver, Locate.by(By.xpath("//*[@id='username']"))); - Assert.assertTrue(inputUserName.isPresent(), "Element present."); - inputUserName.asserts().assertIsPresent(); - } - - @Test - public void testT02_isDisplayed() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/login"); - - final GuiElement inputUserName = new GuiElement(driver, Locate.by(By.xpath("//*[@id='username']"))); - Assert.assertTrue(inputUserName.isDisplayed(), "Element displayed."); - inputUserName.asserts().assertIsDisplayed(); - } - - @Test - public void testT03_type() { - - final String valueExpected = "foobar"; - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/login"); - - final GuiElement inputUserName = new GuiElement(driver, Locate.by(By.xpath("//*[@id='username']"))); - inputUserName.asserts().assertIsDisplayed(); - - inputUserName.type(valueExpected); - final String valueActual = inputUserName.getAttribute("value"); - Assert.assertEquals(valueActual, valueExpected, "Typed text equals."); - } - - @Test - public void testT04_getNumberOfFoundElements() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/login"); - - final GuiElement inputElementMatchesTwo = new GuiElement(driver, Locate.by(By.cssSelector("input"))); - Assert.assertEquals(inputElementMatchesTwo.getNumberOfFoundElements(), 2, "Input elements found"); - } - - @Test - public void testT05_sendKeys() { - - final String valueExpected = "foo bar"; - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/login"); - - final GuiElement inputUserName = new GuiElement(driver, Locate.by(By.xpath("//*[@id='username']"))); - inputUserName.asserts().assertIsDisplayed(); - - inputUserName.sendKeys(valueExpected); - Assert.assertEquals(inputUserName.getAttribute("value"), valueExpected, "Typed text equals."); - } - - @Test - public void testT06_getTagName() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/login"); - - final GuiElement inputUserName = new GuiElement(driver, Locate.by(By.xpath("//*[@id='username']"))); - inputUserName.asserts().assertIsDisplayed(); - - Assert.assertEquals(inputUserName.getTagName(), "input", "Tag name equals."); - } - - @Test - public void testT07_click() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/add_remove_elements/"); - - final GuiElement buttonAdd = new GuiElement(driver, Locate.by(By.xpath("//button[text()='Add Element']"))); - buttonAdd.asserts().assertIsDisplayed(); - - buttonAdd.click(); - final GuiElement buttonRemove = new GuiElement(driver, Locate.by(By.xpath("//button[text()='Delete']"))); - buttonRemove.asserts().assertIsDisplayed(); - - buttonRemove.click(); - buttonRemove.asserts().assertIsNotDisplayed(); - } - - @Test - public void testT08_hover() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/hovers"); - - final GuiElement itemToHover = new GuiElement(driver, Locate.by(By.xpath("(//*[@class='figure'])[1]"))); - final GuiElement itemToDisplayed = new GuiElement(driver, Locate.by(By.xpath("//h5[contains(text(), 'user1')]"))); - - itemToHover.asserts().assertIsDisplayed(); - itemToDisplayed.asserts().assertIsNotDisplayed(); - - itemToHover.hover(); - Assert.assertTrue(itemToDisplayed.isDisplayed(), "Item displayed"); - itemToDisplayed.asserts().assertIsDisplayed(); - } - - @Test - public void testT09_getSelectElement() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/dropdown"); - - final GuiElement selectDropdown = new GuiElement(driver, Locate.by(By.xpath("//select[@id='dropdown']"))); - selectDropdown.asserts().assertIsDisplayed(); - - final Select selectElement = selectDropdown.getSelectElement(); - final List options = selectElement.getOptions(); - Assert.assertNotEquals(options.size(), 0, "One ore more options shown."); - - selectElement.selectByIndex(2); - Assert.assertEquals(selectElement.getFirstSelectedOption().getText(), "Option 2", "Selected option matches."); - } - - @Test - public void testT10_selectCheckbox() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/checkboxes"); - - final GuiElement checkboxOne = new GuiElement(driver, Locate.by(By.xpath("(//input[@type='checkbox'])[1]"))); - Assert.assertFalse(checkboxOne.isSelected(), "Checkbox selected."); - - checkboxOne.select(); - Assert.assertTrue(checkboxOne.isSelected(), "Checkbox selected."); - } - - @Test - public void testT11_deselectCheckbox() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/checkboxes"); - - final GuiElement checkboxOne = new GuiElement(driver, Locate.by(By.xpath("(//input[@type='checkbox'])[2]"))); - Assert.assertTrue(checkboxOne.isSelected(), "Checkbox selected."); - - checkboxOne.deselect(); - Assert.assertFalse(checkboxOne.isSelected(), "Checkbox selected."); - } - - @Test - public void testT12_isVisible() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/"); - - final GuiElement link = new GuiElement(driver, Locate.by(By.linkText("WYSIWYG Editor"))); - Assert.assertTrue(link.isVisible(true), "Link is visible"); - } - - @Test - public void testT13_getSubElement() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/forgot_password"); - - final GuiElement contentWrapper = new GuiElement(driver, Locate.by(By.xpath("//*[@id='content']"))); - contentWrapper.asserts().assertIsDisplayed(); - - final GuiElement formElement = contentWrapper.getSubElement(Locate.by(By.xpath(".//*[@id='forgot_password']"))); - formElement.asserts().assertIsDisplayed(); - - final GuiElement buttonElement = formElement.getSubElement(Locate.by(By.xpath(".//button[@id='form_submit']"))); - buttonElement.asserts().assertIsDisplayed(); - } - - @Test - public void testT14_shadowDom() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/shadowdom"); - - final GuiElement shadowRoot = new GuiElement(driver, Locate.by(By.xpath("(//my-paragraph)[2]"))).shadowRoot(); - shadowRoot.asserts().assertIsPresent(); - - final GuiElement shadowRootSubElement = shadowRoot.getSubElement(Locate.by(By.xpath(".//li[contains(text(), 'In a list!')]"))); - shadowRootSubElement.asserts().assertIsDisplayed(); - } - - @Test - public void testT15_withFrames() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/nested_frames"); - - final GuiElement frameTop = new GuiElement(driver, Locate.by(By.xpath("//frame[@name='frame-top']"))); - frameTop.asserts().assertIsPresent(); - - final GuiElement frameBottom = new GuiElement(driver, Locate.by(By.xpath(".//frame[@name='frame-bottom']"))); - frameBottom.asserts().assertIsPresent(); - - final GuiElement frameTopMiddle = (GuiElement) frameTop.find(By.xpath("//frame[@name='frame-middle']")); - frameTopMiddle.asserts().assertIsPresent(); - - final GuiElement topMiddleContent = (GuiElement) frameTopMiddle.find(By.xpath("//*[@id='content' and text()='MIDDLE']")); - topMiddleContent.asserts().assertIsPresent(); - - final GuiElement frameTopLeft = frameTop.getSubElement(Locate.by(By.xpath(".//frame[@name='frame-left']"))); - frameTopLeft.asserts().assertIsPresent(); - } - - @Test - public void testT16_contextClick() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/context_menu"); - - final GuiElement elementToClick = new GuiElement(driver, Locate.by(By.xpath("//*[@id='hot-spot']"))); - elementToClick.asserts().assertIsDisplayed(); - elementToClick.contextClick(); - } - - @Test(enabled = false) - public void testTXX_dragAndDropElements() { - - final WebDriver driver = WebDriverManager.getWebDriver(); - driver.get("https://the-internet.herokuapp.com/shadowdom"); - - final GuiElement draggable = new GuiElement(driver, Locate.by(By.xpath("//*[@id='column-a']"))); - final GuiElement dropLocation = new GuiElement(driver, Locate.by(By.xpath("//*[@id='column-b']"))); - - draggable.asserts().assertIsDisplayed(); - dropLocation.asserts().assertIsDisplayed(); - - // TODO action here - - String text = dropLocation.getSubElement(Locate.by(By.xpath("//header"))).getText(); - Assert.assertEquals(text, "A", "A successfully dropped."); - } - - // scroll into view - -} - diff --git a/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/guielement/MobileUiElementTest.java b/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/guielement/MobileUiElementTest.java index fa11ca6b..a228be51 100644 --- a/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/guielement/MobileUiElementTest.java +++ b/appium/src/test/java/eu/tsystems/mms/tic/testframework/mobile/test/guielement/MobileUiElementTest.java @@ -23,16 +23,22 @@ package eu.tsystems.mms.tic.testframework.mobile.test.guielement; import eu.tsystems.mms.tic.testframework.annotations.Fails; +import eu.tsystems.mms.tic.testframework.appium.Browsers; +import eu.tsystems.mms.tic.testframework.mobile.driver.SafariMobileConfig; import eu.tsystems.mms.tic.testframework.mobile.test.AbstractAppiumTest; import eu.tsystems.mms.tic.testframework.pageobjects.TestableUiElement; import eu.tsystems.mms.tic.testframework.pageobjects.UiElement; import eu.tsystems.mms.tic.testframework.pageobjects.UiElementFinder; +import eu.tsystems.mms.tic.testframework.report.model.steps.TestStep; import eu.tsystems.mms.tic.testframework.testing.AssertProvider; import eu.tsystems.mms.tic.testframework.testing.UiElementFinderFactoryProvider; +import eu.tsystems.mms.tic.testframework.useragents.ChromeConfig; + import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.Select; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.util.List; @@ -42,10 +48,21 @@ */ public class MobileUiElementTest extends AbstractAppiumTest implements UiElementFinderFactoryProvider, AssertProvider { - private final UiElementFinder finder = UI_ELEMENT_FINDER_FACTORY.create(WEB_DRIVER_MANAGER.getWebDriver()); + @BeforeClass + public void initBrowser() { + WEB_DRIVER_MANAGER.setUserAgentConfig(Browsers.mobile_chrome, (ChromeConfig) options -> { + options.setAcceptInsecureCerts(true); + }); + + WEB_DRIVER_MANAGER.setUserAgentConfig(Browsers.mobile_safari, (SafariMobileConfig) options -> { + options.acceptInsecureCerts(); + }); + } @Test public void testT01_isPresent() { + TestStep.begin(""); + final WebDriver driver = WEB_DRIVER_MANAGER.getWebDriver(); driver.get("https://the-internet.herokuapp.com/login"); @@ -269,6 +286,7 @@ public void testTXX_dragAndDropElements() { // scroll into view private UiElement find(By by) { + UiElementFinder finder = UI_ELEMENT_FINDER_FACTORY.create(WEB_DRIVER_MANAGER.getWebDriver()); return finder.find(by); } diff --git a/appium/src/test/resources/test.properties b/appium/src/test/resources/test.properties index d7b11907..20a6ec6c 100644 --- a/appium/src/test/resources/test.properties +++ b/appium/src/test/resources/test.properties @@ -1,7 +1,9 @@ - #tt.browser=mobile_chrome #tt.browser=mobile_safari +#tt.browser=android +tt.browser=ios + #tt.baseurl=https://the-internet.herokuapp.com/ #tt.mobile.device.query.ios=@os='ios' and @category='PHONE'