Skip to content

Commit

Permalink
#2: Added jUnit Example
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Eroshenko committed May 7, 2013
1 parent e892786 commit eab13d1
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 1 deletion.
9 changes: 8 additions & 1 deletion htmlelements-junit-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>htmlelements-junit-example</artifactId>
<name>Yandex QATools HtmlElements Example using jUnit</name>
<packaging>jar</packaging>

<properties>
<htmlelements.version>1.11-SNAPSHOT</htmlelements.version>
Expand All @@ -28,7 +30,12 @@
</dependency>
<dependency>
<groupId>ru.yandex.qatools.htmlelements</groupId>
<artifactId>htmlelements-all</artifactId>
<artifactId>htmlelements-java</artifactId>
<version>${htmlelements.version}</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.htmlelements</groupId>
<artifactId>htmlelements-matchers</artifactId>
<version>${htmlelements.version}</version>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package my.company.web.elements;

import org.openqa.selenium.support.FindBy;
import ru.yandex.qatools.htmlelements.element.Button;
import ru.yandex.qatools.htmlelements.element.HtmlElement;
import ru.yandex.qatools.htmlelements.element.TextInput;

/**
* @author Artem Eroshenko eroshenkoam
* 5/6/13, 5:13 PM
*/
public class SearchArrow extends HtmlElement {

@FindBy(xpath = ".//input[@class='b-form-input__input']")
public TextInput requestInput;

@FindBy(xpath = ".//input[@class='b-form-button__input']")
public Button searchButton;

public void searchFor(String request) {
requestInput.clear();
requestInput.sendKeys(request);
searchButton.click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package my.company.web.elements;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import ru.yandex.qatools.htmlelements.element.HtmlElement;

import java.util.List;

/**
* @author Artem Eroshenko eroshenkoam
* 5/6/13, 5:13 PM
*/
public class SearchResults extends HtmlElement {

@SuppressWarnings("unused")
@FindBy(xpath = ".//li[contains(@class, 'b-serp-item_js_inited')]")
private List<WebElement> searchItems;

public List<WebElement> getSearchItems() {
return searchItems;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package my.company.web.pages;

import my.company.web.elements.SearchArrow;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator;

/**
* @author Artem Eroshenko eroshenkoam
* 5/6/13, 5:14 PM
*/
public class MainPage {

private WebDriver driver;

@FindBy(className = "b-morda-search-form")
private SearchArrow searchArrow;

public MainPage(final WebDriver driver) {
PageFactory.initElements(new HtmlElementDecorator(driver), this);
this.driver = driver;
}

public SearchPage searchFor(String request) {
this.searchArrow.searchFor(request);
return new SearchPage(driver);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package my.company.web.pages;

import my.company.web.elements.SearchArrow;
import my.company.web.elements.SearchResults;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator;

/**
* @author Artem Eroshenko eroshenkoam
* 5/6/13, 5:15 PM
*/
public class SearchPage {

@SuppressWarnings("unused")
private WebDriver driver;

@FindBy(className = "b-serp-list")
@SuppressWarnings("unused")
private SearchResults searchResults;

@FindBy(className = "b-morda-search-form")
@SuppressWarnings("unused")
private SearchArrow searchArrow;

public SearchPage(WebDriver driver) {
PageFactory.initElements(new HtmlElementDecorator(driver), this);
this.driver = driver;
}

public void searchFor(String request) {
this.searchArrow.searchFor(request);
}

public SearchResults getSearchResults() {
return this.searchResults;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package my.company.web;

import my.company.web.pages.MainPage;
import my.company.web.pages.SearchPage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.junit.Assert.assertThat;
import static ru.yandex.qatools.htmlelements.matchers.WebElementMatchers.exists;

/**
* @author Artem Eroshenko eroshenkoam
* 5/6/13, 2:51 PM
*/
public class SearchingByRequestTest {

private final int DEFAULT_RESULTS_COUNT;

public WebDriver driver = new FirefoxDriver();

public SearchingByRequestTest() {
DEFAULT_RESULTS_COUNT = 10;
}

@Before
public void loadStartPage() {
driver.get("http://www.yandex.ru");
}

@Test
public void afterSearchingUserShouldSeSearchResults() {
MainPage mainPage = new MainPage(driver);
SearchPage page = mainPage.searchFor("Yandex");
assertThat(page.getSearchResults(), exists());
assertThat(page.getSearchResults().getSearchItems(), hasSize(DEFAULT_RESULTS_COUNT));
}

@After
public void killWebDriver() {
driver.quit();
}
}

0 comments on commit eab13d1

Please sign in to comment.