Skip to content
Open
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,38 @@
<aspectj.version>1.9.1</aspectj.version>
<allure.version>2.17.3</allure.version>
<jackson.version>2.13.2</jackson.version>
<testng.version>7.5</testng.version>
<json-simple.version>1.1.1</json-simple.version>
<java-appium.version>7.6.0</java-appium.version>
<lombok.version>1.18.22</lombok.version>
<commons-io.version>2.11.0</commons-io.version>
<selenide-appium.version>1.7.4</selenide-appium.version>
<slf4j.version>1.7.36</slf4j.version>
<qala.version>2.5.1</qala.version>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<version>${testng.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<version>${json-simple.version}</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.6.0</version>
<version>${java-appium.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -53,7 +61,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>${commons-io.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
<dependency>
Expand All @@ -71,20 +79,20 @@
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide-appium</artifactId>
<version>1.7.4</version>
<version>${selenide-appium.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.qala.datagen/qala-datagen -->
<dependency>
<groupId>io.qala.datagen</groupId>
<artifactId>qala-datagen</artifactId>
<version>2.5.1</version>
<version>${qala.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/gu/mobile/android/pages/BasePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@
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();
return new SettingsPage();
}

public BasePage goBack() {
if(((AndroidDriver) WebDriverRunner.getWebDriver()).isKeyboardShown()) {
((AndroidDriver) WebDriverRunner.getWebDriver()).hideKeyboard();
}
UIHelper.hideKeyboard();
Selenide.back();
return this;
}
Expand Down
32 changes: 15 additions & 17 deletions src/main/java/org/gu/mobile/android/pages/ListPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
}
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/gu/mobile/android/pages/MainPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/gu/mobile/android/pages/SettingsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public void verifyCategoriesList(List<String> expected) {
$(settingsItem).click();
UIHelper.selectOption("Categories list");

List<String> list = new ArrayList<>($$(MobileBy.id("com.slava.buylist:id/title")).texts());
List<String> 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<String> actual = list.stream().distinct().collect(Collectors.toList());
Assert.assertEquals(actual, expected);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/gu/mobile/android/utils/UIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.$;
Expand Down Expand Up @@ -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();
}
}
}
8 changes: 0 additions & 8 deletions src/test/java/org/gu/mobile/android/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
6 changes: 4 additions & 2 deletions src/test/java/org/gu/mobile/android/ExitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
6 changes: 3 additions & 3 deletions src/test/java/org/gu/mobile/android/FlowTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down