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
My first mobile autotest :) #82
Open
22f
wants to merge
4
commits into
autoschool:master
Choose a base branch
from
22f:androidTesting
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
4 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
57 changes: 57 additions & 0 deletions
57
commons-module/src/test/java/ru/qatools/school/mobiletests/MyFirstMobileTest.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,57 @@ | ||
| 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; | ||
|
|
||
| import java.net.MalformedURLException; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.greaterThan; | ||
|
|
||
| /** | ||
| * Created by aasx on 18.05.2016. | ||
| */ | ||
| public class MyFirstMobileTest { | ||
|
|
||
| private static final String STATION_FROM = "Арбатская"; | ||
| private static final String STATION_TO = "Борисово"; | ||
| private static final int MINIMUM_TRAVEL_TIME = 10; | ||
|
|
||
| @Rule | ||
| public MobileDriverRule mobileDriverRule = new MobileDriverRule(); | ||
| private MobileSteps steps; | ||
|
|
||
| @Before | ||
| public void initSteps() throws MalformedURLException { | ||
| steps = new MobileSteps(mobileDriverRule.getDriver()); | ||
| } | ||
|
|
||
| @Test | ||
| @Title("Время в пути между станциями должно быть не менее 10 минут ") | ||
| public void expectTravelTimeBetweenTwoDifferentStationMoreThatTenMinutes() throws MalformedURLException { | ||
| steps.clickOn(onMainScreen().getStationFrom()); | ||
| steps.enterText(onSelectStationScreen().getStationName(), STATION_FROM); | ||
| steps.clickOn(onSelectStationScreen().getFirstCityFromSuggestList()); | ||
| steps.clickOn(onMainScreen().getStationTo()); | ||
| steps.enterText(onSelectStationScreen().getStationName(), STATION_TO); | ||
| steps.clickOn(onSelectStationScreen().getFirstCityFromSuggestList()); | ||
| assertThat("время в пути должно быть больше минимального времени между двумя станциями", | ||
| onMainScreen().getTimeNeededInMinutes(), greaterThan(MINIMUM_TRAVEL_TIME)); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| private MainScreen onMainScreen() throws MalformedURLException { | ||
| return new MainScreen(mobileDriverRule.getDriver()); | ||
| } | ||
|
|
||
| private SelectStationScreen onSelectStationScreen() throws MalformedURLException { | ||
| return new SelectStationScreen(mobileDriverRule.getDriver()); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
| package ru.qatools.school.rules; | ||
|
|
||
| import org.junit.rules.ExternalResource; | ||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.remote.DesiredCapabilities; | ||
| import org.openqa.selenium.remote.RemoteWebDriver; | ||
|
|
||
| import java.net.URL; | ||
|
|
||
| /** | ||
| * Created by aasx on 18.05.2016. | ||
| */ | ||
| public class MobileDriverRule extends ExternalResource { | ||
| private WebDriver driver; | ||
| private DesiredCapabilities desiredCapabilities; | ||
|
|
||
| protected void before() throws Throwable { | ||
| 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"); | ||
| desiredCapabilities.setCapability("unicodeKeyboard", "true"); | ||
| this.driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities); | ||
| } | ||
|
|
||
| public WebDriver getDriver() { | ||
| return driver; | ||
| } | ||
|
|
||
| protected void after() { | ||
| desiredCapabilities.setCapability("resetKeyboard", "true"); | ||
| driver.quit(); | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
| 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; | ||
|
|
||
| /** | ||
| * Created by aasx on 18.05.2016. | ||
| */ | ||
| public class MainScreen { | ||
| @Name("Station FROM") | ||
| @FindBy(id = "ru.yandex.metro:id/tv_from_name") | ||
| private HtmlElement StationFrom; | ||
|
|
||
|
|
||
| @Name("Station TO") | ||
| @FindBy(id = "ru.yandex.metro:id/tv_to_name") | ||
| private HtmlElement StationTo; | ||
|
|
||
| @Name("Time in way") | ||
| @FindBy(id = "ru.yandex.metro:id/tv_time") | ||
| private HtmlElement timeNeeded; | ||
|
|
||
| public MainScreen(WebDriver driver) { | ||
| PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this); | ||
| } | ||
|
|
||
| public HtmlElement getTimeNeeded() { | ||
| return timeNeeded; | ||
| } | ||
|
|
||
| public int getTimeNeededInMinutes() { | ||
| int time = Integer.parseInt(timeNeeded.getText().substring(1, 3)); | ||
| return time; | ||
| } | ||
|
|
||
| public HtmlElement getStationFrom() { | ||
| return StationFrom; | ||
| } | ||
|
|
||
| public HtmlElement getStationTo() { | ||
| return StationTo; | ||
| } | ||
|
|
||
|
|
||
| } | ||
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
| 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; | ||
|
|
||
| /** | ||
| * Created by aasx on 18.05.2016. | ||
| */ | ||
| public class SelectStationScreen { | ||
| @Name("Enter station name") | ||
| @FindBy(id = "ru.yandex.metro:id/filterTextId") | ||
| private HtmlElement stationName; | ||
|
|
||
| @Name("Suggest List") | ||
| @FindBy(id = "ru.yandex.metro:id/txtStationName") | ||
| private List<HtmlElement> suggestList; | ||
|
|
||
| public SelectStationScreen(WebDriver driver) { | ||
| PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this); | ||
| } | ||
|
|
||
| public HtmlElement getFirstCityFromSuggestList() { | ||
| return suggestList.get(0); | ||
| } | ||
|
|
||
| public HtmlElement getStationName() { | ||
| return stationName; | ||
| } | ||
|
|
||
| } |
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
| package ru.qatools.school.steps.mobilesteps; | ||
|
|
||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.WebElement; | ||
| 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; | ||
|
|
||
| /** | ||
| * Created by aasx on 18.05.2016. | ||
| */ | ||
| public class MobileSteps { | ||
| private WebDriver driver; | ||
|
|
||
| public MobileSteps(WebDriver driver) { | ||
| this.driver = driver; | ||
| } | ||
|
|
||
|
|
||
| @Step("Кликаем по элементу {0} ") | ||
| public void clickOn(HtmlElement element) { | ||
| element.click(); | ||
| } | ||
|
|
||
| @Step("Вводим текст «{1}» в элемент «{0}»") | ||
| public void enterText(HtmlElement element, String text) { | ||
| element.sendKeys(text); | ||
| } | ||
|
|
||
| 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.
Мы же не можем точно знать, сколько цифр в числе минут?
И я бы вынес логику в другое место, оставив в этом классе только представление.
Uh oh!
There was an error while loading. Please reload this page.
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.
@OneginES
именно поэтому я сделал отдельный метод в минутах
если там будут часы, то сделаю отдельный парсер через регулярки и умножение на 60 :)