Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print html path if savePageSource is true. #590

Merged
merged 4 commits into from Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/java/com/codeborne/selenide/ex/ErrorMessages.java
Expand Up @@ -39,7 +39,17 @@ public static String screenshot(String screenshotPath) {
if (!Configuration.screenshots) {
return "";
}
return "\nScreenshot: " + screenshotPath;

if (screenshotPath == null || screenshotPath.isEmpty()) {
return "\nScreenshot: " + screenshotPath;
}

if (Configuration.savePageSource) {
String htmlFilePath = getHtmlFilePath(screenshotPath);
return "\nScreenshot: " + screenshotPath + "\nPage source: " + htmlFilePath;
} else {
return "\nScreenshot: " + screenshotPath;
}
}

public static String causedBy(Throwable cause) {
Expand All @@ -58,4 +68,8 @@ public static String jsErrors(List<String> jsErrors) {
}
return "\nJavascript Errors: " + jsErrors;
}

private static String getHtmlFilePath(String screenshotPath) {
return screenshotPath.substring(0, screenshotPath.lastIndexOf('.')) + ".html";
}
}
14 changes: 14 additions & 0 deletions src/test/java/com/codeborne/selenide/ex/ErrorMessagesTest.java
Expand Up @@ -26,6 +26,7 @@ public static void rememberOldValues() {
@AfterClass
public static void restoreOldValues() {
Configuration.screenshots = true;
Configuration.savePageSource = true;
Configuration.reportsUrl = reportsUrl;
screenshots = new ScreenShotLaboratory();
}
Expand All @@ -35,6 +36,7 @@ public void setUp() {
Configuration.screenshots = true;
screenshots = mock(ScreenShotLaboratory.class);
doCallRealMethod().when(screenshots).formatScreenShotPath();
Configuration.savePageSource = false;
}

@Test
Expand Down Expand Up @@ -81,4 +83,16 @@ public void doesNotAddScreenshot_if_screenshotsAreDisabled() {
assertEquals("", screenshot);
verify(screenshots, never()).takeScreenShot();
}

@Test
public void printHtmlPath_if_savePageSourceIsEnabled() {
Configuration.savePageSource = true;
Configuration.reportsUrl = "http://ci.mycompany.com/job/666/artifact/";
String currentDir = System.getProperty("user.dir");
doReturn(currentDir + "/test-result/12345.png").when(screenshots).takeScreenShot();

String screenshot = ErrorMessages.screenshot();
assertEquals("\nScreenshot: http://ci.mycompany.com/job/666/artifact/test-result/12345.png"
+ "\nPage source: http://ci.mycompany.com/job/666/artifact/test-result/12345.html", screenshot);
}
}
Expand Up @@ -54,6 +54,7 @@ public void elementNotFound() {
assertStartsWith("Element not found {h9}\n" +
"Expected: text 'expected text'\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.\n" +
"Caused by: NoSuchElementException:", expected);
assertEquals("http://ci.org/build/reports/tests/" + browser + "/1.jpg", expected.getScreenshot());
Expand All @@ -69,6 +70,7 @@ public void elementTextDoesNotMatch() {
assertEquals("Element should have text 'expected text' {h2}\n" +
"Element: '<h2>Dropdown list</h2>'\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.", expected.toString());
assertEquals("http://ci.org/build/reports/tests/" + browser + "/1.jpg", expected.getScreenshot());
}
Expand All @@ -83,6 +85,7 @@ public void elementAttributeDoesNotMatch() {
assertEquals("Element should have attribute name=header {h2}\n" +
"Element: '<h2>Dropdown list</h2>'\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.", expected.toString());
}
}
Expand All @@ -97,6 +100,7 @@ public void wrapperTextDoesNotMatch() {
assertEquals("Element should have text 'expected text' {By.tagName: h2}\n" +
"Element: '<h2>Dropdown list</h2>'\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.", expected.toString());
}
}
Expand All @@ -110,6 +114,7 @@ public void clickHiddenElement() {
assertEquals("Element should be visible {#theHiddenElement}\n" +
"Element: '<div id=\"theHiddenElement\" displayed:false></div>'\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.", elementShouldExist.toString());
assertEquals("http://ci.org/build/reports/tests/" + browser + "/1.jpg", elementShouldExist.getScreenshot());
}
Expand All @@ -124,6 +129,7 @@ public void pageObjectElementTextDoesNotMatch() {
assertEquals("Element should have text 'expected text' {By.tagName: h2}\n" +
"Element: '<h2>Dropdown list</h2>'\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.", expected.toString());
}
}
Expand All @@ -137,6 +143,7 @@ public void pageObjectWrapperTextDoesNotMatch() {
assertEquals("Element should have text 'expected text' {By.tagName: h2}\n" +
"Element: '<h2>Dropdown list</h2>'\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.", expected.toString());
}
}
Expand All @@ -159,6 +166,7 @@ public void clickUnexistingWrappedElement() {
assertStartsWith("Element not found {By.id: invalid_id}\n" +
"Expected: visible\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.\n" +
"Caused by: NoSuchElementException:", e);
}
Expand All @@ -178,6 +186,7 @@ public void existingElementShouldNotExist() {
assertEquals("Element should not exist {h2}\n" +
"Element: '<h2>Dropdown list</h2>'\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.", e.toString());
}
}
Expand All @@ -191,6 +200,7 @@ public void nonExistingElementShouldNotBeHidden() {
assertStartsWith("Element not found {h14}\n" +
"Expected: not hidden\n" +
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n" +
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n" +
"Timeout: 1.500 s.\n" +
"Caused by: NoSuchElementException:", e);
}
Expand All @@ -206,7 +216,8 @@ public void clickingNonClickableElement() {
} catch (UIAssertionError e) {
assertContains(e, "is not clickable at point",
"Other element would receive the click",
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg");
"Screenshot: http://ci.org/build/reports/tests/" + browser + "/1.jpg\n",
"Page source: http://ci.org/build/reports/tests/" + browser + "/1.html\n");
}
}

Expand Down