diff --git a/README.md b/README.md
index 3415f5c..7812746 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,22 @@ Repository contains UI tests for ShoppingApp
* `src/main/java/org/gu/mobile/android/utils` - utility classes for common actions
* `src/test/java/org/gu/mobile/android` - tests themselves
+## Manual setup
+* IDE with Java support ([IntelliJ IDEA CE](https://www.jetbrains.com/idea/download/) is recommended)
+* Java 11 or later (in IntelliJ IDEA: File->Project Structure->Platform Settings->SDK->Download)
+* Appium Desktop ([Release from GitHub](https://github.com/appium/appium-desktop/releases))
+* Appium Inspector ([Release from GitHub](https://github.com/appium/appium-inspector/releases))
+
+## Setup via brew
+* Install [Homebrew](https://brew.sh/)
+`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
+* Install Java11 `brew install java11`
+* Install IntelliJ IDEA `brew install --cask intellij-idea-ce`
+* Create symlink for java `sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk`
+* Install NodeJS `brew install node`
+* Install Appium `npm install -g appium`
+* Run appium server in npm console `appium`
+
## Run tests in IntelliJ IDEA
### Using TestNG
diff --git a/pom.xml b/pom.xml
index f36545b..49f3a08 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,6 +14,14 @@
1.9.1
2.17.3
2.13.2
+ 7.5
+ 1.1.1
+ 7.6.0
+ 1.18.22
+ 2.11.0
+ 1.7.4
+ 1.7.36
+ 2.5.1
@@ -21,23 +29,23 @@
org.testng
testng
- 7.5
+ ${testng.version}
com.googlecode.json-simple
json-simple
- 1.1.1
+ ${json-simple.version}
io.appium
java-client
- 7.6.0
+ ${java-appium.version}
org.projectlombok
lombok
- 1.18.22
+ ${lombok.version}
provided
@@ -53,7 +61,7 @@
commons-io
commons-io
- 2.11.0
+ ${commons-io.version}
@@ -71,20 +79,20 @@
com.codeborne
selenide-appium
- 1.7.4
+ ${selenide-appium.version}
org.slf4j
slf4j-simple
- 1.7.36
+ ${slf4j.version}
test
io.qala.datagen
qala-datagen
- 2.5.1
+ ${qala.version}
diff --git a/src/main/java/org/gu/mobile/android/driver/DriverFactory.java b/src/main/java/org/gu/mobile/android/driver/DriverFactory.java
index 0b00bec..527ea85 100644
--- a/src/main/java/org/gu/mobile/android/driver/DriverFactory.java
+++ b/src/main/java/org/gu/mobile/android/driver/DriverFactory.java
@@ -32,6 +32,7 @@ private static DesiredCapabilities getCapabilities() {
setCapability(PLATFORM_NAME, Constants.CONFIG.getPlatformName());
setCapability(PLATFORM_VERSION, Constants.CONFIG.getPlatformVersion());
setCapability(APP, System.getProperty("appPath", Constants.CONFIG.getAppPath()));
+ setCapability(FULL_RESET, true);
setCapability(AUTOMATION_NAME, Constants.CONFIG.getAutomationName());
setCapability("project", "GridU project");
setCapability("build", "GridU build");
diff --git a/src/main/java/org/gu/mobile/android/pages/BasePage.java b/src/main/java/org/gu/mobile/android/pages/BasePage.java
index 4c95586..e803dd3 100644
--- a/src/main/java/org/gu/mobile/android/pages/BasePage.java
+++ b/src/main/java/org/gu/mobile/android/pages/BasePage.java
@@ -4,12 +4,13 @@
import com.codeborne.selenide.WebDriverRunner;
import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
+import org.gu.mobile.android.utils.UIHelper;
import org.openqa.selenium.By;
import static com.codeborne.selenide.Selenide.$;
public class BasePage {
- private final By settingsButton = MobileBy.id("com.slava.buylist:id/button1");
+ private final By settingsButton = MobileBy.id("button1");
public SettingsPage openSetting() {
$(settingsButton).click();
@@ -17,9 +18,7 @@ public SettingsPage openSetting() {
}
public BasePage goBack() {
- if(((AndroidDriver) WebDriverRunner.getWebDriver()).isKeyboardShown()) {
- ((AndroidDriver) WebDriverRunner.getWebDriver()).hideKeyboard();
- }
+ UIHelper.hideKeyboard();
Selenide.back();
return this;
}
diff --git a/src/main/java/org/gu/mobile/android/pages/ListPage.java b/src/main/java/org/gu/mobile/android/pages/ListPage.java
index e3fcc53..f74e786 100644
--- a/src/main/java/org/gu/mobile/android/pages/ListPage.java
+++ b/src/main/java/org/gu/mobile/android/pages/ListPage.java
@@ -19,23 +19,23 @@
import static com.codeborne.selenide.Selenide.$$;
public class ListPage extends BasePage {
- private final By titleLabel = MobileBy.id("com.slava.buylist:id/textView1");
- private final By productNameInput = MobileBy.id("com.slava.buylist:id/editText1");
- private final By addProductButton = MobileBy.id("com.slava.buylist:id/button2");
- private final By priceInput = MobileBy.id("com.slava.buylist:id/editText2");
- private final By currencyLabel = MobileBy.id("com.slava.buylist:id/value");
- private final By amountInput = MobileBy.id("com.slava.buylist:id/editText3");
- private final By unitsList = MobileBy.id("com.slava.buylist:id/spinner1");
+ private final By titleLabel = MobileBy.id("textView1");
+ private final By productNameInput = MobileBy.id("editText1");
+ private final By addProductButton = MobileBy.id("button2");
+ private final By priceInput = MobileBy.id("editText2");
+ private final By currencyLabel = MobileBy.id("value");
+ private final By amountInput = MobileBy.id("editText3");
+ private final By unitsList = MobileBy.id("spinner1");
private final String textFormatString = "new UiSelector().text(\"%s\")";
- private final By commentInput = MobileBy.id("com.slava.buylist:id/editText4");
- private final By categoriesList = MobileBy.id("com.slava.buylist:id/spinner2");
+ private final By commentInput = MobileBy.id("editText4");
+ private final By categoriesList = MobileBy.id("spinner2");
private final By selectedItem = MobileBy.id("android:id/text1");
- private final By itemsList = MobileBy.id("com.slava.buylist:id/listView1");
- private final By itemTitleLabel = MobileBy.id("com.slava.buylist:id/title");
- private final By itemCommentLabel = MobileBy.id("com.slava.buylist:id/str1");
- private final By itemAmountLabel = MobileBy.id("com.slava.buylist:id/TextView01");
- private final By itemPriceLabel = MobileBy.id("com.slava.buylist:id/textView1");
+ private final By itemsList = MobileBy.id("listView1");
+ private final By itemTitleLabel = MobileBy.id("title");
+ private final By itemCommentLabel = MobileBy.id("str1");
+ private final By itemAmountLabel = MobileBy.id("TextView01");
+ private final By itemPriceLabel = MobileBy.id("textView1");
private final By yesModalButton = MobileBy.id("android:id/button1");
private final By noModalButton = MobileBy.id("android:id/button2");
@@ -86,9 +86,7 @@ public MainPage cancel() {
@Step("Back to main page")
public MainPage goToMainPage() {
- if(((AndroidDriver)WebDriverRunner.getWebDriver()).isKeyboardShown()) {
- ((AndroidDriver) WebDriverRunner.getWebDriver()).hideKeyboard();
- }
+ UIHelper.hideKeyboard();
Selenide.back();
return new MainPage();
}
diff --git a/src/main/java/org/gu/mobile/android/pages/MainPage.java b/src/main/java/org/gu/mobile/android/pages/MainPage.java
index 15374a0..8d0bf73 100644
--- a/src/main/java/org/gu/mobile/android/pages/MainPage.java
+++ b/src/main/java/org/gu/mobile/android/pages/MainPage.java
@@ -18,25 +18,25 @@
import static io.appium.java_client.appmanagement.ApplicationState.RUNNING_IN_BACKGROUND;
public class MainPage extends BasePage {
- private final By titleLabel = MobileBy.id("com.slava.buylist:id/textView1");
+ private final By titleLabel = MobileBy.id("textView1");
- private final By listTitleLabel = MobileBy.id("com.slava.buylist:id/title");
+ private final By listTitleLabel = MobileBy.id("title");
private final String listTitleXpath = "//android.widget.TextView[@id=\"com.slava.buylist:id/title\n\" and contains(@text, \"%s\")]";
- private final By nameInput = MobileBy.id("com.slava.buylist:id/editText1");
- private final By addListButton = MobileBy.id("com.slava.buylist:id/button2");
- private final By infoString = MobileBy.id("com.slava.buylist:id/str1");
+ private final By nameInput = MobileBy.id("editText1");
+ private final By addListButton = MobileBy.id("button2");
+ private final By infoString = MobileBy.id("str1");
- private final By deleteButton = MobileBy.id("com.slava.buylist:id/imageView1");
+ private final By deleteButton = MobileBy.id("mageView1");
private final String deleteButtonXpath = "//android.widget.TextView[@resource-id=\"com.slava.buylist:id/title\" and contains(@text, \"%s\")]/following-sibling::android.widget.ImageView[@resource-id=\"com.slava.buylist:id/imageView1\"]";
private final By okToDeleteButton = MobileBy.id("android:id/button1");
- private final By yesButton = MobileBy.id("com.slava.buylist:id/button1");
- private final By noButton = MobileBy.id("com.slava.buylist:id/button2");
- private final By thumbsUpButton = MobileBy.id("com.slava.buylist:id/imageButton1");
+ private final By yesButton = MobileBy.id("button1");
+ private final By noButton = MobileBy.id("button2");
+ private final By thumbsUpButton = MobileBy.id("imageButton1");
- private final By adsContainer = MobileBy.id("com.slava.buylist:id/adView");
+ private final By adsContainer = MobileBy.id("adView");
private final By adsTitle = MobileBy.className("android.widget.TextView");
private final By adsContent = MobileBy.className("android.webkit.WebView");
@@ -110,7 +110,7 @@ public void openPlayStore() {
}
public MainPage removeAllLists() {
- $$(MobileBy.id("com.slava.buylist:id/title")).texts().forEach(this::removeList);
+ $$(MobileBy.id("title")).texts().forEach(this::removeList);
return this;
}
}
diff --git a/src/main/java/org/gu/mobile/android/pages/SettingsPage.java b/src/main/java/org/gu/mobile/android/pages/SettingsPage.java
index d65208d..9735a06 100644
--- a/src/main/java/org/gu/mobile/android/pages/SettingsPage.java
+++ b/src/main/java/org/gu/mobile/android/pages/SettingsPage.java
@@ -32,13 +32,13 @@ public void verifyCategoriesList(List expected) {
$(settingsItem).click();
UIHelper.selectOption("Categories list");
- List list = new ArrayList<>($$(MobileBy.id("com.slava.buylist:id/title")).texts());
+ List list = new ArrayList<>($$(MobileBy.id("title")).texts());
$(MobileBy.AndroidUIAutomator("new UiScrollable("
+ "new UiSelector().scrollable(true)).scrollIntoView("
+ "new UiSelector().textContains(\"Alcohol, tobacco\"));")).shouldBe(visible);
- list.addAll($$(MobileBy.id("com.slava.buylist:id/title")).texts());
+ list.addAll($$(MobileBy.id("title")).texts());
List actual = list.stream().distinct().collect(Collectors.toList());
Assert.assertEquals(actual, expected);
}
diff --git a/src/main/java/org/gu/mobile/android/utils/UIHelper.java b/src/main/java/org/gu/mobile/android/utils/UIHelper.java
index 930892c..67ec822 100644
--- a/src/main/java/org/gu/mobile/android/utils/UIHelper.java
+++ b/src/main/java/org/gu/mobile/android/utils/UIHelper.java
@@ -6,6 +6,7 @@
import io.appium.java_client.MobileBy;
import io.appium.java_client.PerformsTouchActions;
import io.appium.java_client.TouchAction;
+import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.interactions.Actions;
import static com.codeborne.selenide.Selenide.$;
@@ -36,4 +37,10 @@ public static void tapByElement (SelenideElement element) {
public static void longTap(SelenideElement element) {
new Actions(element.getWrappedDriver()).clickAndHold(element).perform();
}
+
+ public static void hideKeyboard() {
+ if(((AndroidDriver)WebDriverRunner.getWebDriver()).isKeyboardShown()) {
+ ((AndroidDriver) WebDriverRunner.getWebDriver()).hideKeyboard();
+ }
+ }
}
diff --git a/src/test/java/org/gu/mobile/android/BaseTest.java b/src/test/java/org/gu/mobile/android/BaseTest.java
index 261ef28..cecf2c2 100644
--- a/src/test/java/org/gu/mobile/android/BaseTest.java
+++ b/src/test/java/org/gu/mobile/android/BaseTest.java
@@ -40,12 +40,4 @@ public void before() throws IOException {
driver.rotate(ScreenOrientation.PORTRAIT);
WebDriverRunner.setWebDriver(driver);
}
-
- @AfterSuite
- public void after() {
- ((AppiumDriver)WebDriverRunner.getWebDriver()).closeApp();
- if(WebDriverRunner.hasWebDriverStarted()) {
- Selenide.closeWebDriver();
- }
- }
}
diff --git a/src/test/java/org/gu/mobile/android/ExitTests.java b/src/test/java/org/gu/mobile/android/ExitTests.java
index ce35def..fc9a57a 100644
--- a/src/test/java/org/gu/mobile/android/ExitTests.java
+++ b/src/test/java/org/gu/mobile/android/ExitTests.java
@@ -5,15 +5,17 @@
import org.testng.annotations.Test;
public class ExitTests extends BaseTest {
+ private MainPage mainPage = new MainPage();
+
@Test(description = "Cancel app exit")
@Description("Exit app and cancel it")
public void noToStay() {
- new MainPage().exitAndCancel();
+ mainPage.exitAndCancel();
}
@Test(description = "Proceed to app exit")
@Description("Exit app and confirm it")
public void yesToExit() {
- new MainPage().exitAndConfirm();
+ mainPage.exitAndConfirm();
}
}
diff --git a/src/test/java/org/gu/mobile/android/FlowTests.java b/src/test/java/org/gu/mobile/android/FlowTests.java
index 6de5844..5ba5ca0 100644
--- a/src/test/java/org/gu/mobile/android/FlowTests.java
+++ b/src/test/java/org/gu/mobile/android/FlowTests.java
@@ -45,10 +45,10 @@ public void cancelListCreating() {
@AfterMethod
public void openMainPage() {
- while(!$(MobileBy.id("com.slava.buylist:id/textView1")).text().equals("Buy list")) {
+ while(!$(MobileBy.id("textView1")).text().equals("Buy list")) {
Selenide.back();
- if($(MobileBy.id("com.slava.buylist:id/button1")).text().equalsIgnoreCase("yes")) {
- $(MobileBy.id("com.slava.buylist:id/button1")).click();
+ if($(MobileBy.id("button1")).text().equalsIgnoreCase("yes")) {
+ $(MobileBy.id("button1")).click();
}
}
new MainPage().removeAllLists();