Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ios section to settings.json, added basic tests #6

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

Expand Down
53 changes: 53 additions & 0 deletions src/test/java/samples/ios/IOSBasicInteractionsTest.java
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need folder 'sample'?
why we test only 'Basic'? Our goal is up to 90% of the code should be covered with tests. Will the rest of tests developed later?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes , will cover the other functionality in next prs

private IOSDriver<?> driver;

@BeforeClass
public void setUp() {
driver = (IOSDriver<?>) ApplicationManager.getApplication().getDriver();
}

@AfterClass
public void tearDown() {
ApplicationManager.getApplication().quit();
}

@Test
public void testSendKeysToInput() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, rename all the tests to patter like:
testShouldBePossibleToSendTextToElement()

do we really need MainScreen for such tests? Can we use elements factory directly here?

MainScreen mainScreen = new MainScreen();
Assert.assertTrue(mainScreen.isDisplayed(), "Main screen of app wasn't loaded");
mainScreen.enterTextToFirstField("Hello World!");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move "Hello World!" to local method variable

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we verify the same twice?

Assert.assertEquals(twoItemsAlertScreen.getTitle(), "Cool title");
driver.switchTo().alert().accept();
Assert.assertTrue(mainScreen.isDisplayed(), "Main screen wasn't opened");
}
}
30 changes: 30 additions & 0 deletions src/test/java/samples/ios/testapp/screens/MainScreen.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
26 changes: 26 additions & 0 deletions src/test/java/samples/ios/testapp/screens/TwoItemsAlertScreen.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Binary file added src/test/resources/apps/TestApp.app.zip
Binary file not shown.
9 changes: 9 additions & 0 deletions src/test/resources/iosTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="iOS demo test suite">
<test name="Basic interactions tests">
<classes>
<class name="samples.ios.IOSBasicInteractionsTest"/>
</classes>
</test>
</suite>
9 changes: 9 additions & 0 deletions src/test/resources/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
"capabilities": {
"deviceName": "Android Emulator"
}
},
"ios": {
"applicationPath": "./src/test/resources/apps/TestApp.app.zip",
mialeska marked this conversation as resolved.
Show resolved Hide resolved
"capabilities": {
"deviceName": "iOS Simulator",
"automationName": "XCUITest",
"platformName": "iOS",
arazantsau marked this conversation as resolved.
Show resolved Hide resolved
"udid": "<SIMULATOR_ID/DEVICE_ID>"
}
}
},
"timeouts": {
Expand Down