diff --git a/.gitignore b/.gitignore index 8327858..2509aea 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ *.war *.nar *.ear -*.zip *.tar.gz *.rar diff --git a/src/test/java/samples/ios/IOSBasicInteractionsTest.java b/src/test/java/samples/ios/IOSBasicInteractionsTest.java new file mode 100644 index 0000000..a99f567 --- /dev/null +++ b/src/test/java/samples/ios/IOSBasicInteractionsTest.java @@ -0,0 +1,53 @@ +package samples.ios; + +import aquality.appium.application.ApplicationManager; +import io.appium.java_client.ios.IOSDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import samples.ios.testapp.screens.MainScreen; +import samples.ios.testapp.screens.TwoItemsAlertScreen; + +public class IOSBasicInteractionsTest { + private IOSDriver driver; + + @BeforeClass + public void setUp() { + driver = (IOSDriver) ApplicationManager.getApplication().getDriver(); + } + + @AfterClass + public void tearDown() { + ApplicationManager.getApplication().quit(); + } + + @Test + public void testSendKeysToInput() { + MainScreen mainScreen = new MainScreen(); + Assert.assertTrue(mainScreen.isDisplayed(), "Main screen of app wasn't loaded"); + mainScreen.enterTextToFirstField("Hello World!"); + Assert.assertEquals(mainScreen.getValueFromFirstTextBox(), "Hello World!"); + } + + @Test + public void testAcceptAlertViaButtons() { + MainScreen mainScreen = new MainScreen(); + mainScreen.tapShowAlert(); + TwoItemsAlertScreen twoItemsAlertScreen = new TwoItemsAlertScreen(); + Assert.assertTrue(twoItemsAlertScreen.isDisplayed(), "Alert wasn't opened"); + Assert.assertEquals(twoItemsAlertScreen.getTitle(), "Cool title"); + twoItemsAlertScreen.acceptAlert(); + } + + @Test + public void testAcceptAlertViaDriver() { + MainScreen mainScreen = new MainScreen(); + mainScreen.tapShowAlert(); + TwoItemsAlertScreen twoItemsAlertScreen = new TwoItemsAlertScreen(); + Assert.assertTrue(twoItemsAlertScreen.isDisplayed(), "Alert wasn't opened"); + Assert.assertEquals(twoItemsAlertScreen.getTitle(), "Cool title"); + driver.switchTo().alert().accept(); + Assert.assertTrue(mainScreen.isDisplayed(), "Main screen wasn't opened"); + } +} diff --git a/src/test/java/samples/ios/testapp/screens/MainScreen.java b/src/test/java/samples/ios/testapp/screens/MainScreen.java new file mode 100644 index 0000000..776d613 --- /dev/null +++ b/src/test/java/samples/ios/testapp/screens/MainScreen.java @@ -0,0 +1,30 @@ +package samples.ios.testapp.screens; + +import aquality.appium.elements.interfaces.IButton; +import aquality.appium.elements.interfaces.ITextBox; +import aquality.appium.screens.IOSScreen; +import io.appium.java_client.MobileBy; +import org.openqa.selenium.By; + +public class MainScreen extends IOSScreen { + + private static final By FIRST_TEXT_FIELD_LOCATOR = MobileBy.AccessibilityId("TextField1"); + private final ITextBox txbFirstTextField = getElementFactory().getTextBox(FIRST_TEXT_FIELD_LOCATOR, "First text field"); + private final IButton btnShowAlert = getElementFactory().getButton(MobileBy.AccessibilityId("show alert"), "Show alert"); + + public MainScreen() { + super(FIRST_TEXT_FIELD_LOCATOR, "Main screen"); + } + + public String getValueFromFirstTextBox() { + return txbFirstTextField.getText(); + } + + public void enterTextToFirstField(String value) { + txbFirstTextField.typeSecret(value); + } + + public void tapShowAlert() { + btnShowAlert.click(); + } +} diff --git a/src/test/java/samples/ios/testapp/screens/TwoItemsAlertScreen.java b/src/test/java/samples/ios/testapp/screens/TwoItemsAlertScreen.java new file mode 100644 index 0000000..a5ba031 --- /dev/null +++ b/src/test/java/samples/ios/testapp/screens/TwoItemsAlertScreen.java @@ -0,0 +1,26 @@ +package samples.ios.testapp.screens; + +import aquality.appium.elements.interfaces.IButton; +import aquality.appium.elements.interfaces.ILabel; +import aquality.appium.screens.IOSScreen; +import io.appium.java_client.MobileBy; +import org.openqa.selenium.By; + +public class TwoItemsAlertScreen extends IOSScreen { + + private static final By TITLE_LOCATOR = MobileBy.AccessibilityId("Cool title"); + private final ILabel lblAlertTitle = getElementFactory().getLabel(MobileBy.AccessibilityId("Cool title"), "Title"); + private final IButton btnOk = getElementFactory().getButton(MobileBy.AccessibilityId("OK"), "OK"); + + public TwoItemsAlertScreen() { + super(TITLE_LOCATOR, "Alert screen"); + } + + public String getTitle() { + return lblAlertTitle.getText(); + } + + public void acceptAlert() { + btnOk.click(); + } +} diff --git a/src/test/resources/apps/TestApp.app.zip b/src/test/resources/apps/TestApp.app.zip new file mode 100644 index 0000000..52e4c21 Binary files /dev/null and b/src/test/resources/apps/TestApp.app.zip differ diff --git a/src/test/resources/iosTests.xml b/src/test/resources/iosTests.xml new file mode 100644 index 0000000..90bbae6 --- /dev/null +++ b/src/test/resources/iosTests.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/test/resources/settings.json b/src/test/resources/settings.json index f806747..e8e04a5 100644 --- a/src/test/resources/settings.json +++ b/src/test/resources/settings.json @@ -21,6 +21,15 @@ "capabilities": { "deviceName": "Android Emulator" } + }, + "ios": { + "applicationPath": "./src/test/resources/apps/TestApp.app.zip", + "capabilities": { + "deviceName": "iOS Simulator", + "automationName": "XCUITest", + "platformName": "iOS", + "udid": "" + } } }, "timeouts": {