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 26
mobile application test #83
Open
arrumm
wants to merge
3
commits into
autoschool:master
Choose a base branch
from
arrumm:mobitest
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
53 changes: 53 additions & 0 deletions
53
commons-module/src/test/java/ru/qatools/school/mobiletests/MobileTest.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,53 @@ | ||
| 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.screens.MainScreen; | ||
| import ru.qatools.school.screens.SelectStationScreen; | ||
| import ru.qatools.school.steps.mobilesteps.MobileSteps; | ||
| import ru.yandex.qatools.allure.annotations.Title; | ||
|
|
||
| /** | ||
| * @author arrumm 19.05.2016. | ||
| */ | ||
| public class MobileTest { | ||
|
|
||
| private static final String DEPARTURE_STATION = "Arbatskaya"; | ||
| private static final String DESTINATION_STATION = "Borisovo"; | ||
| private static final int MIN_TIME = 10; | ||
|
|
||
| private MobileSteps mobileSteps; | ||
|
|
||
| @Rule | ||
| public MobileDriverRule remoteWebDriverRule = new MobileDriverRule(); | ||
|
|
||
| @Before | ||
| public void initSteps() { | ||
| mobileSteps = new MobileSteps(remoteWebDriverRule.getDriver()); | ||
| } | ||
|
|
||
| @Test | ||
| @Title("Ожидаемое время поездки должно быть больше 10 минут") | ||
| public void shouldSeeGreaterTime() { | ||
| mobileSteps.tapOn(onMainScreen().fromStationField()); | ||
| mobileSteps.sendKeysTo(onSelectStationScreen().stationNameField(), DEPARTURE_STATION); | ||
| mobileSteps.tapOn(onSelectStationScreen().getFirstStation()); | ||
|
|
||
| mobileSteps.tapOn(onMainScreen().toStationField()); | ||
| mobileSteps.sendKeysTo(onSelectStationScreen().stationNameField(), DESTINATION_STATION); | ||
| mobileSteps.tapOn(onSelectStationScreen().getFirstStation()); | ||
|
|
||
| mobileSteps.shouldSeeGreaterThan(onMainScreen().timeField(), MIN_TIME); | ||
| } | ||
|
|
||
| private MainScreen onMainScreen() { | ||
| return new MainScreen(remoteWebDriverRule.getDriver()); | ||
| } | ||
|
|
||
| private SelectStationScreen onSelectStationScreen() { | ||
| return new SelectStationScreen(remoteWebDriverRule.getDriver()); | ||
| } | ||
|
|
||
| } |
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
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
| 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.MalformedURLException; | ||
| import java.net.URL; | ||
|
|
||
| /** | ||
| * @author arrumm 19.05.2016. | ||
| */ | ||
| public class MobileDriverRule extends ExternalResource { | ||
|
|
||
| private RemoteWebDriver driver; | ||
|
|
||
| protected void before() throws MalformedURLException { | ||
|
|
||
| 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"); | ||
|
|
||
| this.driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities); | ||
| } | ||
|
|
||
| protected void after() { | ||
| driver.quit(); | ||
| } | ||
|
|
||
| public RemoteWebDriver getDriver() { | ||
| return driver; | ||
| } | ||
|
|
||
| } |
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
| package ru.qatools.school.screens; | ||
|
|
||
| import org.openqa.selenium.remote.RemoteWebDriver; | ||
| 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 arrumm 19.05.2016. | ||
| */ | ||
| public class MainScreen { | ||
|
|
||
| public MainScreen(RemoteWebDriver driver) { | ||
| PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this); | ||
| } | ||
|
|
||
| @Name("Поле ввода начальной станции") | ||
| @FindBy(id = "tv_from_name") | ||
| private HtmlElement fromStationField; | ||
|
|
||
| @Name("Поле ввода конечной станции") | ||
| @FindBy(id = "tv_to_name") | ||
| private HtmlElement toStationField; | ||
|
|
||
| @Name("Поле ожидаемое время поездки") | ||
| @FindBy(id = "tv_time") | ||
| private HtmlElement timeField; | ||
|
|
||
| public HtmlElement fromStationField() { | ||
| return fromStationField; | ||
| } | ||
|
|
||
| public HtmlElement toStationField() { | ||
| return toStationField; | ||
| } | ||
|
|
||
| public HtmlElement timeField() { | ||
| return timeField; | ||
| } | ||
|
|
||
| } |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
| package ru.qatools.school.screens; | ||
|
|
||
| import org.openqa.selenium.remote.RemoteWebDriver; | ||
| 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 arrumm 19.05.2016. | ||
| */ | ||
| public class SelectStationScreen { | ||
|
|
||
| public SelectStationScreen(RemoteWebDriver driver) { | ||
| PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this); | ||
| } | ||
|
|
||
| @Name("Поле ввода названия станции") | ||
| @FindBy(id = "filterTextId") | ||
| private HtmlElement stationNameField; | ||
|
|
||
| @Name("Список результатов поиска станции для выбора") | ||
| @FindBy(id = "txtStationName") | ||
| private List<HtmlElement> stationSuggestResults; | ||
|
|
||
| public HtmlElement stationNameField(){ | ||
| return stationNameField; | ||
| } | ||
|
|
||
| public List<HtmlElement> stationSuggestResults(){ | ||
| return stationSuggestResults; | ||
| } | ||
|
|
||
| public HtmlElement getFirstStation() { | ||
| return stationSuggestResults.get(0); | ||
| } | ||
| } |
78 changes: 78 additions & 0 deletions
78
steps-module/src/main/java/ru/qatools/school/steps/mobilesteps/mobilesteps.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,78 @@ | ||
| package ru.qatools.school.steps.mobilesteps; | ||
|
|
||
| import org.openqa.selenium.remote.RemoteWebDriver; | ||
| 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 java.util.regex.Pattern; | ||
|
|
||
| import static org.hamcrest.Matchers.greaterThan; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| /** | ||
| * @author arrumm 19.05.2016. | ||
| */ | ||
| public class MobileSteps { | ||
|
|
||
| private RemoteWebDriver driver; | ||
|
|
||
| public MobileSteps(RemoteWebDriver driver) { | ||
| this.driver = driver; | ||
| } | ||
|
|
||
| @Step("Открываем главный экран") | ||
| public void openMainScreen() { | ||
|
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. Не очень понимаю, что тут происходит, и зачем нужен этот метод, он же вроде не используется нигде |
||
| driver.getCurrentUrl(); | ||
| } | ||
|
|
||
| @Step("Открываем экран с выбором станций") | ||
| public void openStationScreen() { | ||
| driver.getCurrentUrl(); | ||
| } | ||
|
|
||
| private MainScreen onMainScreen() { | ||
| return new MainScreen(driver); | ||
| } | ||
|
|
||
| private SelectStationScreen onSelectStationScreen() { | ||
| return new SelectStationScreen(driver); | ||
| } | ||
|
|
||
| @Step("Тапаем элемент {0}") | ||
| public void tapOn(HtmlElement element) { | ||
| element.click(); | ||
| } | ||
|
|
||
| @Step("Вводим текст {1} в элемент {0}") | ||
| public void sendKeysTo(HtmlElement element, String keys) { | ||
| element.sendKeys(keys); | ||
| } | ||
|
|
||
| @Step() | ||
| public void shouldSeeGreaterThan(HtmlElement element, int time){ | ||
|
|
||
| int hours=0, minutes=0; | ||
| String strTime = element.getText(); | ||
|
|
||
| String regex = "([\\s]+h+[\\s]|[\\s]+min)"; | ||
|
|
||
| Pattern p = Pattern.compile(regex); | ||
|
|
||
| String[] mas = p.split(strTime); | ||
|
|
||
| if (mas.length == 1){ | ||
| minutes = Integer.parseInt(mas[0].replaceAll("\\s", "")); | ||
| } | ||
| else{ | ||
| hours = Integer.parseInt(mas[0].replaceAll("\\s", "")); | ||
| minutes = Integer.parseInt(mas[1].replaceAll("\\s", "")); | ||
| } | ||
|
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. Тут мы используем четыре регулярных выражения для поискам двух чисел в одной строке. Многовато, имхо. :) |
||
|
|
||
| assertThat("Value should be greater", | ||
| hours*60+minutes, | ||
| greaterThan(time)); | ||
| } | ||
|
|
||
| } | ||
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.
А тебе эта зависимость точно нужна?