This repository was archived by the owner on Oct 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Mobile tests #89
Open
gladnik
wants to merge
1
commit into
autoschool:master
Choose a base branch
from
gladnik:mobile-tests-branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mobile tests #89
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
commons-module/src/test/java/ru/qatools/school/mobiletests/MetroAppTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package ru.qatools.school.mobiletests; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import ru.qatools.school.rules.MobileDriverRule; | ||
| import ru.qatools.school.steps.mobilesteps.MetroAppSteps; | ||
| import ru.yandex.qatools.allure.annotations.Title; | ||
|
|
||
| /** | ||
| * @author gladnik (Nikolai Gladkov) | ||
| */ | ||
| public class MetroAppTests { | ||
|
|
||
| private static final String FIRST_STATION = "Arbatskaya"; | ||
| private static final String SECOND_STATION = "Borisovo"; | ||
| private static final int MIN_TIME = 10; | ||
|
|
||
| private MetroAppSteps metroSteps; | ||
|
|
||
| @Rule | ||
| public MobileDriverRule androidDriverRule = new MobileDriverRule(); | ||
|
|
||
| @Before | ||
| public void initSteps() { | ||
| metroSteps = new MetroAppSteps(androidDriverRule.getDriver()); | ||
| } | ||
|
|
||
| @Test | ||
| @Title("Время в пути между станциями должно быть больше минимального") | ||
| public void shouldGetRouteExceedingMinTime() { | ||
| metroSteps.setRoute(FIRST_STATION, SECOND_STATION); | ||
| metroSteps.shouldSeeTravelTimeGreaterThan(MIN_TIME); | ||
| } | ||
|
|
||
| } |
33 changes: 33 additions & 0 deletions
33
steps-module/src/main/java/ru/qatools/school/rules/MobileDriverRule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package ru.qatools.school.rules; | ||
|
|
||
| import org.junit.rules.ExternalResource; | ||
| import org.openqa.selenium.remote.DesiredCapabilities; | ||
| import org.openqa.selenium.remote.RemoteWebDriver; | ||
|
|
||
| import java.net.URL; | ||
|
|
||
| /** | ||
| * @author gladnik (Nikolai Gladkov) | ||
| */ | ||
| public class MobileDriverRule extends ExternalResource { | ||
|
|
||
| private RemoteWebDriver driver; | ||
|
|
||
| protected void before() throws Throwable { | ||
| DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); | ||
| desiredCapabilities.setCapability("platformName", "Android"); | ||
| desiredCapabilities.setCapability("deviceName", "Android"); | ||
| desiredCapabilities.setCapability("app", "http://autoschool.github.io/files/ya-metro.apk"); | ||
| desiredCapabilities.setCapability("appWaitActivity", "ru.yandex.metro.MainActivity"); | ||
| driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities); | ||
| } | ||
|
|
||
| protected void after() { | ||
| driver.quit(); | ||
| } | ||
|
|
||
| public RemoteWebDriver getDriver() { | ||
| return driver; | ||
| } | ||
|
|
||
| } |
45 changes: 45 additions & 0 deletions
45
steps-module/src/main/java/ru/qatools/school/screens/MainScreen.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package ru.qatools.school.screens; | ||
|
|
||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.support.FindBy; | ||
| import org.openqa.selenium.support.PageFactory; | ||
| import ru.yandex.qatools.htmlelements.annotations.Name; | ||
| import ru.yandex.qatools.htmlelements.element.HtmlElement; | ||
| import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator; | ||
| import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementLocatorFactory; | ||
|
|
||
| /** | ||
| * @author gladnik (Nikolai Gladkov) | ||
| */ | ||
| public class MainScreen { | ||
|
|
||
| @Name("Поле ввода начальной станции") | ||
| @FindBy(id = "ru.yandex.metro:id/tv_from_name") | ||
| private HtmlElement tvFromName; | ||
|
|
||
| @Name("Поле ввода конечной станции") | ||
| @FindBy(id = "ru.yandex.metro:id/tv_to_name") | ||
| private HtmlElement tvToName; | ||
|
|
||
| @Name("Время в пути") | ||
| @FindBy(id = "ru.yandex.metro:id/tv_time") | ||
| private HtmlElement tvTime; | ||
|
|
||
|
|
||
| public MainScreen(WebDriver driver) { | ||
| PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this); | ||
| } | ||
|
|
||
| public HtmlElement tvFromName() { | ||
| return tvFromName; | ||
| } | ||
|
|
||
| public HtmlElement tvToName() { | ||
| return tvToName; | ||
| } | ||
|
|
||
| public HtmlElement tvTime() { | ||
| return tvTime; | ||
| } | ||
|
|
||
| } | ||
46 changes: 46 additions & 0 deletions
46
steps-module/src/main/java/ru/qatools/school/screens/SelectStationScreen.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package ru.qatools.school.screens; | ||
|
|
||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.support.FindBy; | ||
| import org.openqa.selenium.support.PageFactory; | ||
| import ru.yandex.qatools.htmlelements.annotations.Name; | ||
| import ru.yandex.qatools.htmlelements.element.HtmlElement; | ||
| import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator; | ||
| import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementLocatorFactory; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * @author gladnik (Nikolai Gladkov) | ||
| */ | ||
| public class SelectStationScreen { | ||
|
|
||
| @Name("Поле ввода для поиска станции") | ||
| @FindBy(id = "ru.yandex.metro:id/filterTextId") | ||
| private HtmlElement filterTextId; | ||
|
|
||
| @Name("Названия найденных станций") | ||
| @FindBy(id = "ru.yandex.metro:id/txtStationName") | ||
| private List<HtmlElement> foundStations; | ||
|
|
||
| @Name("Название первой из найденных станций") | ||
| private HtmlElement firstStation; | ||
|
|
||
|
|
||
| public SelectStationScreen(WebDriver driver) { | ||
| PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this); | ||
| } | ||
|
|
||
| public HtmlElement filterTextId() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не самое говорящее название метода =) |
||
| return filterTextId; | ||
| } | ||
|
|
||
| public List<HtmlElement> foundStations() { | ||
| return foundStations; | ||
| } | ||
|
|
||
| public HtmlElement firstStation() { | ||
| firstStation = foundStations.get(0); | ||
| return firstStation; | ||
| } | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
steps-module/src/main/java/ru/qatools/school/steps/mobilesteps/MetroAppSteps.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package ru.qatools.school.steps.mobilesteps; | ||
|
|
||
| import org.openqa.selenium.WebDriver; | ||
| import ru.qatools.school.screens.MainScreen; | ||
| import ru.qatools.school.screens.SelectStationScreen; | ||
| import ru.yandex.qatools.allure.annotations.Step; | ||
| import ru.yandex.qatools.htmlelements.element.HtmlElement; | ||
|
|
||
| import static org.hamcrest.Matchers.greaterThan; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| /** | ||
| * @author gladnik (Nikolai Gladkov) | ||
| */ | ||
| public class MetroAppSteps { | ||
|
|
||
| private WebDriver driver; | ||
|
|
||
| public MetroAppSteps(WebDriver driver) { | ||
| this.driver = driver; | ||
| } | ||
|
|
||
| @Step("Тапаем по [{0}]") | ||
| public static void tapOn(HtmlElement element) { | ||
| element.click(); | ||
| } | ||
|
|
||
| @Step("Вводим «{1}» в «{0}»") | ||
| public static void sendText(HtmlElement element, String text) { | ||
| element.sendKeys(text); | ||
| } | ||
|
|
||
| @Step("Меняем станцию отправления на «{0}»") | ||
| public void changeDepartureStationBySelectScreen(String newStationName) { | ||
| tapOn(onMainScreen().tvFromName()); | ||
| sendText(onSelectStationScreen().filterTextId(), newStationName); | ||
| tapOn(onSelectStationScreen().firstStation()); | ||
| } | ||
|
|
||
| @Step("Меняем станцию назанчения на «{0}»") | ||
| public void changeDestinationStationBySelectScreen(String newStationName) { | ||
| tapOn(onMainScreen().tvToName()); | ||
| sendText(onSelectStationScreen().filterTextId(), newStationName); | ||
| tapOn(onSelectStationScreen().firstStation()); | ||
| } | ||
|
|
||
| @Step("Прокладываем маршрут от «{0}» к «{1}»") | ||
| public void setRoute(String fromStation, String toStation) { | ||
| changeDepartureStationBySelectScreen(fromStation); | ||
| changeDestinationStationBySelectScreen(toStation); | ||
| } | ||
|
|
||
| @Step("Время в пути должно быть больше {0} минут") | ||
| public void shouldSeeTravelTimeGreaterThan(int timeInMinutes) { | ||
| int travelDurationInMinutes; | ||
| String[] timeDescription = onMainScreen().tvTime().getText().trim().split(" "); | ||
| if (timeDescription.length == 2) { | ||
| travelDurationInMinutes = Integer.parseInt(timeDescription[0]); | ||
| } else { | ||
| travelDurationInMinutes = Integer.parseInt(timeDescription[0]) * 60 + Integer.parseInt(timeDescription[2]); | ||
| } | ||
|
|
||
| assertThat("Время в пути должно быть больше", travelDurationInMinutes, greaterThan(timeInMinutes)); | ||
| } | ||
|
|
||
| private MainScreen onMainScreen() { | ||
| return new MainScreen(driver); | ||
| } | ||
|
|
||
| private SelectStationScreen onSelectStationScreen() { | ||
| return new SelectStationScreen(driver); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Достаточно
tv_from_name