Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 ru.yandex.qatools.htmlelements.annotations.Name;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;

/**
* @author totallynotkate (Kate Kocijevska)
*/
public class MobileTests {

public static final String FIRST_STATION = "Arbatskaya";
public static final String SECOND_STATION = "Borisovo";
public static final int TIME = 10;
private MobileSteps mobileSteps;

@Rule
public MobileDriverRule mobileDriverRule = new MobileDriverRule();

@Before
public void initSteps(){
mobileSteps = new MobileSteps(mobileDriverRule.getDriver());
}

@Test
@Title("Время поездки от Арбатской до Борисово должно быть больше 10 минут")
public void shouldSeeGreaterTime(){
SelectStationScreen selectStationScreen = mobileSteps.goToSelectStationScreen(onMainScreen().fromField());
mobileSteps.input(selectStationScreen.stationNameInput(), FIRST_STATION);
mobileSteps.tap(selectStationScreen.stationsList().get(0));

selectStationScreen = mobileSteps.goToSelectStationScreen(onMainScreen().toField());
mobileSteps.input(selectStationScreen.stationNameInput(), SECOND_STATION);
mobileSteps.tap(selectStationScreen.stationsList().get(0));

mobileSteps.shouldSeeTimeGreaterThan(TIME);
}

private MainScreen onMainScreen(){
return new MainScreen(mobileDriverRule.getDriver());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 totallynotkate (Kate Kocijevska)
*/
public class MobileDriverRule extends ExternalResource {
protected 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");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
}

protected void after() {
driver.quit();
}

public RemoteWebDriver getDriver() {
return driver;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 totallynotkate (Kate Kocijevska)
*/
public class MainScreen {
public MainScreen(RemoteWebDriver driver){
PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this);
}

@Name("Поле From")
@FindBy(id = "ru.yandex.metro:id/tv_from_name")
private HtmlElement fromField;

@Name("Поле To")
@FindBy(id = "ru.yandex.metro:id/tv_to_name")
private HtmlElement toField;

@Name("Выезжающая панель")
@FindBy(id="ru.yandex.metro:id/topPanel")
private TopPanel topPanel;

public HtmlElement fromField(){
return fromField;
}

public HtmlElement toField() {
return toField;
}

public TopPanel topPanel() {
return topPanel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 totallynotkate (Kate Kocijevska)
*/
public class SelectStationScreen {
public SelectStationScreen(RemoteWebDriver driver){
PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this);
}

@Name("Поле ввода названия станции")
@FindBy(id = "ru.yandex.metro:id/filterTextId")
private HtmlElement stationNameInput;

@Name("Список станций")
@FindBy(id="ru.yandex.metro:id/txtStationName")
private List<HtmlElement> stationsList;

public HtmlElement stationNameInput() {
return stationNameInput;
}

public List<HtmlElement> stationsList() {
return stationsList;
}
}
25 changes: 25 additions & 0 deletions steps-module/src/main/java/ru/qatools/school/screens/TopPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.qatools.school.screens;

import org.openqa.selenium.Rectangle;
import org.openqa.selenium.support.FindBy;
import ru.yandex.qatools.htmlelements.annotations.Name;
import ru.yandex.qatools.htmlelements.element.HtmlElement;

/**
* @author totallynotkate (Kate Kocijevska)
*/
public class TopPanel extends HtmlElement{

@Name("Время поездки")
@FindBy(id="ru.yandex.metro:id/tv_time")
private HtmlElement rideTimeString;

public HtmlElement rideTimeString() {
return rideTimeString;
}

@Override
public Rectangle getRect() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;

/**
* @author totallynotkate (Kate Kocijevska)
*/
public class MobileSteps {
private RemoteWebDriver driver;

public MobileSteps(RemoteWebDriver driver) {
this.driver = driver;
}

@Step("Тапаем по элементу {0}")
public void tap(HtmlElement element) {
element.click();
}

@Step("Переходим на страницу выбора станции с элемента {0}")
public SelectStationScreen goToSelectStationScreen(HtmlElement element) {
element.click();
return new SelectStationScreen(driver);
}

@Step("Вводим текст {1} в поле {0}")
public void input(HtmlElement element, String text) {
element.sendKeys(text);
}

@Step()
public void shouldSeeTimeGreaterThan(int time) {
assertThat("Неправильное время поездки",
Integer.parseInt(onMainScreen().topPanel().rideTimeString().getText().trim().split(" ")[0]),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Начиная с 61ой минуты что-то пойдёт не так.

greaterThan(time));
}

private MainScreen onMainScreen() {
return new MainScreen(driver);
}
}