This repository has been archived by the owner on Oct 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
commons-module/src/test/java/ru/qatools/school/mobiletests/MobileTests.java
This file contains 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.DefaultSteps; | ||
import ru.yandex.qatools.allure.annotations.Title; | ||
|
||
/** | ||
* @author by onegines (Eugene Kirienko) | ||
*/ | ||
public class MobileTests { | ||
|
||
private static final String STATION_1 = "Arbatskaya"; | ||
private static final String STATION_2 = "Borisovo"; | ||
private static final int MIN_TIME = 10; | ||
|
||
private DefaultSteps defaultSteps; | ||
|
||
@Rule | ||
public MobileDriverRule mobileDriverRule = new MobileDriverRule(); | ||
|
||
// @Rule | ||
// public TPInformerRule tms = new TPInformerRule("onegines"); | ||
|
||
@Before | ||
public void initSteps() { | ||
defaultSteps = new DefaultSteps(mobileDriverRule.getDriver()); | ||
} | ||
|
||
private MainScreen onMainScreen() { | ||
return new MainScreen(mobileDriverRule.getDriver()); | ||
} | ||
|
||
private SelectStationScreen onSelectStationScreen() { | ||
return new SelectStationScreen(mobileDriverRule.getDriver()); | ||
} | ||
|
||
@Test | ||
@Title("Время в пути от Арбатской до Борисово должно быть больше 10 минут") | ||
// @TestCaseId("##") | ||
public void shouldSeeAddWidgetButtonOnPageWithNoQuery() { | ||
defaultSteps.clickOn(onMainScreen().fromField()); | ||
defaultSteps.enterText(onSelectStationScreen().stationNameField(), STATION_1); | ||
defaultSteps.clickOn(onSelectStationScreen().firstResult()); | ||
|
||
defaultSteps.clickOn(onMainScreen().toField()); | ||
defaultSteps.enterText(onSelectStationScreen().stationNameField(), STATION_2); | ||
defaultSteps.clickOn(onSelectStationScreen().firstResult()); | ||
|
||
defaultSteps.shouldSeeTimeMoreThan(onMainScreen().timeField(), MIN_TIME); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
steps-module/src/main/java/ru/qatools/school/rules/MobileDriverRule.java
This file contains 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,34 @@ | ||
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; | ||
|
||
/** | ||
* @author onegines (Eugene Kirienko) | ||
*/ | ||
public class MobileDriverRule extends ExternalResource { | ||
|
||
private WebDriver 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 WebDriver getDriver() { | ||
return driver; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
steps-module/src/main/java/ru/qatools/school/screens/MainScreen.java
This file contains 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,43 @@ | ||
package ru.qatools.school.screens; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.openqa.selenium.support.PageFactory; | ||
import ru.yandex.qatools.htmlelements.annotations.Name; | ||
import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator; | ||
import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementLocatorFactory; | ||
|
||
/** | ||
* @author onegines (Eugene Kirienko) | ||
*/ | ||
public class MainScreen { | ||
|
||
@Name("Поле ввода начальной станции") | ||
@FindBy(id = "layout_from") | ||
private WebElement fromField; | ||
|
||
@Name("Поле ввода конечной станции") | ||
@FindBy(id = "layout_to") | ||
private WebElement toField; | ||
|
||
@Name("Время в пути") | ||
@FindBy(id = "tv_time") | ||
private WebElement timeField; | ||
|
||
public MainScreen(WebDriver driver) { | ||
PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this); | ||
} | ||
|
||
public WebElement fromField() { | ||
return fromField; | ||
} | ||
|
||
public WebElement toField() { | ||
return toField; | ||
} | ||
|
||
public WebElement timeField() { | ||
return timeField; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
steps-module/src/main/java/ru/qatools/school/screens/SelectStationScreen.java
This file contains 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.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.openqa.selenium.support.PageFactory; | ||
import ru.yandex.qatools.htmlelements.annotations.Name; | ||
import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator; | ||
import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementLocatorFactory; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author onegines (Eugene Kirienko) | ||
*/ | ||
public class SelectStationScreen { | ||
|
||
@Name("Поле ввода названия станции") | ||
@FindBy(id = "filterTextId") | ||
private WebElement stationNameField; | ||
|
||
@Name("Поля результата поиска названия станции") | ||
@FindBy(id = "txtStationName") | ||
private List<WebElement> stationNameResults; | ||
|
||
public SelectStationScreen(WebDriver driver) { | ||
PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this); | ||
} | ||
|
||
public WebElement stationNameField() { | ||
return stationNameField; | ||
} | ||
|
||
public WebElement firstResult() { | ||
return stationNameResults.get(0); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
steps-module/src/main/java/ru/qatools/school/steps/mobilesteps/DefaultSteps.java
This file contains 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,49 @@ | ||
package ru.qatools.school.steps.mobilesteps; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import ru.yandex.qatools.allure.annotations.Step; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* @author onegines (Eugene Kirienko) | ||
*/ | ||
public class DefaultSteps { | ||
|
||
private WebDriver driver; | ||
|
||
public DefaultSteps(WebDriver driver) { | ||
this.driver = driver; | ||
} | ||
|
||
|
||
@Step("Кликаем по элементу {0}") | ||
public void clickOn(WebElement element) { | ||
element.click(); | ||
} | ||
|
||
@Step("Вводим текст «{1}» в элемент «{0}»") | ||
public void enterText(WebElement element, String text) { | ||
element.sendKeys(text); | ||
} | ||
|
||
@Step("Время в элементе «{0}» должно быть больше «{1}»") | ||
public void shouldSeeTimeMoreThan(WebElement element, int minTime) { | ||
|
||
String timeInText = element.getText(); | ||
Pattern pattern = Pattern.compile("\\d+"); | ||
Matcher matcher = pattern.matcher(timeInText); | ||
|
||
if (matcher.find()) { | ||
int timeInMinutes = Integer.parseInt(matcher.group()); | ||
assertThat("Неправильное время", timeInMinutes, greaterThan(minTime)); | ||
} else { | ||
throw new NumberFormatException("Can't parse in number: " + timeInText); | ||
} | ||
} | ||
} |