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

}
13 changes: 12 additions & 1 deletion steps-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>


<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А тебе эта зависимость точно нужна?

<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.1.0</version>
</dependency>

</dependencies>

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

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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", ""));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Тут мы используем четыре регулярных выражения для поискам двух чисел в одной строке. Многовато, имхо. :)


assertThat("Value should be greater",
hours*60+minutes,
greaterThan(time));
}

}