Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #336 from just-boris/master
Browse files Browse the repository at this point in the history
add timeout to check hash
  • Loading branch information
just-boris committed Aug 13, 2014
2 parents 28b3829 + 3b51bda commit 64a6d10
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ru.yandex.qatools.allure;

import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.openqa.selenium.WebDriver;

import java.net.URI;

public class UrlFragmentMatcher extends TypeSafeMatcher<WebDriver> {

private String expectedFragment;

public UrlFragmentMatcher(String fragment) {
expectedFragment = fragment;
}

private String getUrlFragment(WebDriver driver) {
return URI.create(driver.getCurrentUrl()).getFragment();
}

@Override
public void describeTo(Description description) {
description.appendText("Fragment should be equal \"").appendText(expectedFragment).appendText("\"");
}

@Override
protected void describeMismatchSafely(WebDriver driver, Description mismatchDescription) {
mismatchDescription.appendText("was \"").appendText(getUrlFragment(driver)).appendText("\"");
}

@Override
protected boolean matchesSafely(WebDriver driver) {
return expectedFragment.equals(getUrlFragment(driver));
}

public static UrlFragmentMatcher hasFragment(String fragment) {
return new UrlFragmentMatcher(fragment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static ru.yandex.qatools.allure.Helpers.existsAndVisible;
import static ru.yandex.qatools.allure.UrlFragmentMatcher.hasFragment;
import static ru.yandex.qatools.matchers.decorators.MatcherDecorators.should;
import static ru.yandex.qatools.matchers.decorators.MatcherDecorators.timeoutHasExpired;

Expand All @@ -27,44 +27,42 @@ public void openBrowser() throws Exception {
}

public void checkHash(String expectedHash) {
String url = rule.driver().getCurrentUrl();
String hash = url.substring(url.indexOf('#'));
assertEquals(expectedHash, hash);
assertThat(rule.driver(), should(hasFragment(expectedHash)).whileWaitingUntil(timeoutHasExpired(SECONDS.toMillis(3))));
}

@Test
public void defectsTab() throws Exception {
page.tabs().defects().click();
checkHash("#/defects");
checkHash("/defects");
}

@Test
public void overviewTab() throws Exception {
page.tabs().overview().click();
checkHash("#/");
checkHash("/");
}

@Test
public void homeTab() throws Exception {
checkHash("#/home");
checkHash("/home");
}

@Test
public void behaviorsTab() throws Exception {
page.tabs().behaviours().click();
checkHash("#/features");
checkHash("/features");
}

@Test
public void graphTab() throws Exception {
page.tabs().graph().click();
checkHash("#/graph");
checkHash("/graph");
}

@Test
public void timelineTab() throws Exception {
page.tabs().timeline().click();
checkHash("#/timeline");
checkHash("/timeline");
}

}

0 comments on commit 64a6d10

Please sign in to comment.