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,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());
}
}
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();
}
}
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));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Мы же не можем точно знать, сколько цифр в числе минут?
И я бы вынес логику в другое место, оставив в этом классе только представление.

Copy link
Copy Markdown
Author

@22f 22f May 19, 2016

Choose a reason for hiding this comment

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

@OneginES
именно поэтому я сделал отдельный метод в минутах
если там будут часы, то сделаю отдельный парсер через регулярки и умножение на 60 :)

return time;
}

public HtmlElement getStationFrom() {
return StationFrom;
}

public HtmlElement getStationTo() {
return StationTo;
}


}
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;
}

}
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);}


}