Skip to content

Commit

Permalink
PR #426: fix failing test in htmlunit
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Jan 6, 2017
1 parent cd2d3a4 commit 7360f8b
Showing 1 changed file with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.WebDriverRunner;
import com.codeborne.selenide.ex.ElementNotFound;
import com.codeborne.selenide.ex.ListSizeMismatch;
import com.codeborne.selenide.ex.UIAssertionError;
import integration.IntegrationTest;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.TakesScreenshot;

import static com.codeborne.selenide.CollectionCondition.exactTexts;
import static com.codeborne.selenide.CollectionCondition.size;
Expand Down Expand Up @@ -43,7 +46,7 @@ public void openPage() {
catch (ElementNotFound expected) {
assertThat(expected.getMessage(), startsWith("Element not found {ul .nonexistent}"));
assertThat(expected.getMessage(), containsString("Expected: [Miller, Julie Mao]"));
assertThat(expected.getScreenshot(), containsString(Configuration.reportsFolder));
assertScreenshot(expected);
assertThat(expected.getCause(), nullValue());
}
/*
Expand Down Expand Up @@ -76,7 +79,7 @@ public void openPage() {
catch (ElementNotFound expected) {
assertThat(expected.getMessage(), startsWith("Element not found {ul .nonexistent.filter(css class 'the-expanse')}"));
assertThat(expected.getMessage(), containsString("Expected: [Miller, Julie Mao]"));
assertThat(expected.getScreenshot(), containsString(Configuration.reportsFolder));
assertScreenshot(expected);
assertThat(expected.getCause(), nullValue());
}
/*
Expand All @@ -99,7 +102,7 @@ public void shouldCondition_WhenFilteredCollection_WithNotSatisfiedCondition() {
catch (ElementNotFound expected) {
assertThat(expected.getMessage(), startsWith("Element not found {ul li.filter(css class 'nonexistent')}"));
assertThat(expected.getMessage(), containsString("Expected: [Miller, Julie Mao]"));
assertThat(expected.getScreenshot(), containsString(Configuration.reportsFolder));
assertScreenshot(expected);
assertThat(expected.getCause(), nullValue());
}
/*
Expand All @@ -122,10 +125,15 @@ public void shouldCondition_WhenInnerCollection_WithNonExistentOuterWebElement()
catch (ElementNotFound expected) {
assertThat(expected.getMessage(), startsWith("Element not found {.nonexistent}"));
assertThat(expected.getMessage(), containsString("Expected: exist")); // todo - is it correct?
assertThat(expected.getScreenshot(), containsString(Configuration.reportsFolder));
assertScreenshot(expected);
assertThat(expected.getCause(), instanceOf(NoSuchElementException.class));
assertThat(expected.getCause().getMessage(),
containsString("Unable to locate element: {\"method\":\"css selector\",\"selector\":\".nonexistent\"}"));
if (WebDriverRunner.isHtmlUnit()) {
assertThat(expected.getCause().getMessage(), containsString("Returned node was not a DOM element"));
}
else {
assertThat(expected.getCause().getMessage(),
containsString("Unable to locate element: {\"method\":\"css selector\",\"selector\":\".nonexistent\"}"));
}
}
/*
Element not found {.nonexistent}
Expand All @@ -149,7 +157,7 @@ public void shouldCondition_WhenInnerCollection_WithNonExistentInnerWebElements(
catch (ElementNotFound expected) {
assertThat(expected.getMessage(), startsWith("Element not found {<ul>/.nonexistent}"));
assertThat(expected.getMessage(), containsString("Expected: [Miller, Julie Mao]"));
assertThat(expected.getScreenshot(), containsString(Configuration.reportsFolder));
assertScreenshot(expected);
assertThat(expected.getCause(), nullValue());
}
/*
Expand Down Expand Up @@ -186,7 +194,7 @@ public void shouldCondition_WhenInnerCollection_WithNonExistentInnerWebElements(
}
catch (ListSizeMismatch expected) {
assertThat(expected.getMessage(), startsWith(": expected: = 3, actual: 2, collection: ul li"));
assertThat(expected.getScreenshot(), containsString(Configuration.reportsFolder));
assertScreenshot(expected);
assertThat(expected.getCause(), nullValue());
}
/*
Expand All @@ -211,7 +219,7 @@ public void shouldCondition_WhenInnerCollection_WithNonExistentInnerWebElements(
}
catch (ListSizeMismatch expected) {
assertThat(expected.getMessage(), startsWith(": expected: = 3, actual: 0, collection: ul .nonexistent"));
assertThat(expected.getScreenshot(), containsString(Configuration.reportsFolder));
assertScreenshot(expected);
assertThat(expected.getCause(), nullValue());
}
/*
Expand All @@ -222,4 +230,10 @@ public void shouldCondition_WhenInnerCollection_WithNonExistentInnerWebElements(
Timeout: 6 s.
*/
}

private void assertScreenshot(UIAssertionError expected) {
if (WebDriverRunner.getWebDriver() instanceof TakesScreenshot) {
assertThat(expected.getScreenshot(), containsString(Configuration.reportsFolder));
}
}
}

0 comments on commit 7360f8b

Please sign in to comment.