-
Notifications
You must be signed in to change notification settings - Fork 20
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
Artem Eroshenko
committed
May 7, 2013
1 parent
e892786
commit eab13d1
Showing
6 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
htmlelements-junit-example/src/main/java/my/company/web/elements/SearchArrow.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,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(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
htmlelements-junit-example/src/main/java/my/company/web/elements/SearchResults.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,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; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
htmlelements-junit-example/src/main/java/my/company/web/pages/MainPage.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,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); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
htmlelements-junit-example/src/main/java/my/company/web/pages/SearchPage.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,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; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
htmlelements-junit-example/src/test/java/my/company/web/SearchingByRequestTest.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,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(); | ||
} | ||
} |