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

Add ability storing of webdriver console and network logs after failing tests #8926

Merged
merged 28 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0fa6a51
change webdriver log level and study how to get most important data J…
Feb 22, 2018
f8cba6f
Test logging
Feb 26, 2018
b5f4e52
Merge branch 'master' into che#8857
Feb 26, 2018
f34a6a7
apply storing logs to SeleniumHandler
Feb 26, 2018
a362d20
final rework of BrowserLogsUtil class and apply renamed methods
Feb 27, 2018
8c668f0
rename methods according to proposals for the PR
Feb 27, 2018
b2167c8
rename method
Feb 27, 2018
360b707
Rename BrowserUtilsLog class, revert DI to the related class. Replace…
Feb 27, 2018
ac41500
remove unnecessary WebDriver injections
Feb 27, 2018
5e1ab4f
add add few logs messages for problem detection
vparfonov Feb 27, 2018
0d00d06
rename method
Feb 27, 2018
b3fe3f4
fix name of methos and javadoc
Feb 27, 2018
85f4efc
remove unnecessary static declarations from the WebDriverLogsReader
Feb 27, 2018
9861ae2
Merge branch 'che#8857' of github.com:eclipse/che into che#8857
vparfonov Feb 28, 2018
b1eab7c
remove unnecessary static declarations from the WebDriverLogsReader.
Feb 27, 2018
97d9bca
Merge branch 'che#8857' of github.com:eclipse/che into che#8857
vparfonov Mar 2, 2018
3db9bf2
Add few log messages on server side
vparfonov Mar 2, 2018
ce0cf6b
Make network logs readable; add websocket logs; remove duplicating pr…
Mar 2, 2018
cec456d
Fix store web driver output error message
Mar 3, 2018
423417f
Add javadocs, fix method names
Mar 3, 2018
44b7466
Merge remote-tracking branch 'origin/master' into che#8857
Mar 3, 2018
a2a2be2
Clean up code
Mar 3, 2018
ae5ede8
Fix time format in webdriver logs
Mar 5, 2018
be9f972
Revert "add add few logs messages for problem detection"
Mar 5, 2018
d33badc
Merge remote-tracking branch 'origin/master' into che#8857
Mar 5, 2018
c8930f2
Revert commit 'add add few logs messages for problem detection'
Mar 5, 2018
66c3ef5
Housekeeping
Mar 5, 2018
925fbf7
Clean up
Mar 5, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion selenium/che-selenium-core/bin/webdriver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ storeTestReport() {
if [[ -f ${TMP_SUITE_PATH} ]]; then
cp ${TMP_SUITE_PATH} target/suite;
fi
zip -qr ${report} target/screenshots target/htmldumps target/workspace-logs target/site target/failsafe-reports target/log target/bin target/suite
zip -qr ${report} target/screenshots target/htmldumps target/workspace-logs target/webdriver-logs target/site target/failsafe-reports target/log target/bin target/suite

echo -e "[TEST] Tests results and reports are saved to ${BLUE}${report}${NO_COLOUR}"
echo "[TEST]"
Expand Down
4 changes: 4 additions & 0 deletions selenium/che-selenium-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-json</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-lang</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ private RemoteWebDriver doCreateDriver(URL webDriverUrl) {
switch (browser) {
case GOOGLE_CHROME:
LoggingPreferences loggingPreferences = new LoggingPreferences();
loggingPreferences.enable(LogType.BROWSER, Level.SEVERE);
loggingPreferences.enable(LogType.PERFORMANCE, Level.ALL);
Copy link
Contributor

@dmytro-ndp dmytro-ndp Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was Level.SEVERE used for some reasons.
@Ohrimenko1988: please, comment on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was used because only browser errors have useful information for us. But it only in case for browser's console output. In other cases (for example "Networking"), logs of other levels may be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ALL levels log also can have important info

loggingPreferences.enable(LogType.BROWSER, Level.ALL);

ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.stream.Stream;
import javax.annotation.PreDestroy;
import javax.validation.constraints.NotNull;
import org.eclipse.che.commons.json.JsonParseException;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.client.TestGitHubServiceClient;
Expand All @@ -50,6 +51,7 @@
import org.eclipse.che.selenium.core.pageobject.PageObjectsInjector;
import org.eclipse.che.selenium.core.user.InjectTestUser;
import org.eclipse.che.selenium.core.user.TestUser;
import org.eclipse.che.selenium.core.webdriver.log.WebDriverLogsReaderFactory;
import org.eclipse.che.selenium.core.workspace.InjectTestWorkspace;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
import org.eclipse.che.selenium.core.workspace.TestWorkspaceLogsReader;
Expand Down Expand Up @@ -93,6 +95,10 @@ public abstract class SeleniumTestHandler
@Named("tests.htmldumps_dir")
private String htmldumpsDir;

@Inject
@Named("tests.webdriverlogs_dir")
private String webDriverLogsDir;

@Inject
@Named("tests.workspacelogs_dir")
private String workspaceLogsDir;
Expand Down Expand Up @@ -128,6 +134,7 @@ public abstract class SeleniumTestHandler
@Inject private TestGitHubServiceClient gitHubClientService;
@Inject private TestWorkspaceLogsReader testWorkspaceLogsReader;
@Inject private SeleniumTestStatistics seleniumTestStatistics;
@Inject private WebDriverLogsReaderFactory webDriverLogsReaderFactory;

private final Injector injector;
private final Map<Long, Object> runningTests = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -302,6 +309,7 @@ private void onTestFinish(ITestResult result) {
captureScreenshot(result);
captureHtmlSource(result);
captureTestWorkspaceLogs(result);
storeWebDriverLogs(result);
}
}

Expand Down Expand Up @@ -464,6 +472,32 @@ private void captureScreenshotsFromOpenedWindows(
});
}

private void storeWebDriverLogs(ITestResult result) {
Set<SeleniumWebDriver> webDrivers = new HashSet<>();
Object testInstance = result.getInstance();
collectInjectedWebDrivers(testInstance, webDrivers);
webDrivers.forEach(webDriver -> storeWebDriverLogs(result, webDriver));
}

private void storeWebDriverLogs(ITestResult result, SeleniumWebDriver webDriver) {
String testReference = getTestReference(result);

try {
String filename = NameGenerator.generate(testReference + "_", 4) + ".log";
Path webDriverLogsDirectory = Paths.get(webDriverLogsDir, filename);
Files.createDirectories(webDriverLogsDirectory.getParent());
Files.write(
webDriverLogsDirectory,
webDriverLogsReaderFactory
.create(webDriver)
.getAllLogs()
.getBytes(Charset.forName("UTF-8")),
StandardOpenOption.CREATE);
} catch (WebDriverException | IOException | JsonParseException e) {
LOG.error(format("Can't store web driver logs related to test %s.", testReference), e);
}
}

private void dumpHtmlCodeFromTheCurrentPage(ITestResult result, SeleniumWebDriver webDriver) {
String testReference = getTestReference(result);
String filename = NameGenerator.generate(testReference + "_", 8) + ".html";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.selenium.core.webdriver.log;

import static java.lang.String.format;
import static org.eclipse.che.selenium.core.webdriver.log.WebDriverLogsReader.LOG_TIME_FORMAT;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
* This class deals with web driver log entry.
*
* @author Dmytro Nochevnov
*/
public class Log {
private Message message;
private long timestamp;

public Message getMessage() {
return message;
}

public void setMessage(Message message) {
this.message = message;
}

boolean isNetworkLog() {
return isNetworkRequest()
|| isNetworkResponse()
|| isWebsocketCreated()
|| isWebsocketRequest()
|| isWebsocketResponse();
}

private boolean isNetworkRequest() {
return "Network.requestWillBeSent".equals(getMessage().getMethod());
}

private boolean isNetworkResponse() {
return "Network.responseReceived".equals(getMessage().getMethod());
}

private boolean isWebsocketCreated() {
return "Network.webSocketCreated".equals(getMessage().getMethod());
}

private boolean isWebsocketRequest() {
return "Network.webSocketFrameSent".equals(getMessage().getMethod());
}

private boolean isWebsocketResponse() {
return "Network.webSocketFrameReceived".equals(getMessage().getMethod());
}

public String getUrl() {
if (hasRequest()) {
return getMessage().getParams().getRequest().getUrl();

} else if (hasResponse()) {
return getMessage().getParams().getResponse().getUrl();

} else if (hasParams() && getMessage().getParams().getUrl() != null) {
return getMessage().getParams().getUrl();
}

return "";
}

public String getRequestId() {
if (hasParams()) {
return getMessage().getParams().getRequestId();
}

return "";
}

public long getTimestamp() {
return timestamp;
}

public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}

private String getRequestMethod() {
if (hasRequest()) {
return getMessage().getParams().getRequest().getMethod();
}

return "";
}

private String getResponseStatus() {
if (hasResponse()) {
return getMessage().getParams().getResponse().getStatus();
}

return "";
}

private String getPayloadData() {
if (hasResponse()) {
return getMessage().getParams().getResponse().getPayloadData();
}

return "";
}

private boolean hasRequest() {
return hasParams() && getMessage().getParams().getRequest() != null;
}

private boolean hasResponse() {
return hasParams() && getMessage().getParams().getResponse() != null;
}

private boolean hasParams() {
return getMessage() != null && getMessage().getParams() != null;
}

private String formatTime(long timestamp) {
return new SimpleDateFormat(LOG_TIME_FORMAT).format(new Date(timestamp));
}

@Override
public String toString() {
String prefix = format("%s (id: %s)", formatTime(getTimestamp()), getRequestId());

if (isNetworkRequest()) {
return format("%s [REQUEST] %s %s\n", prefix, getRequestMethod(), getUrl());

} else if (isNetworkResponse()) {
return format("%s [RESPONSE] %s %s\n", prefix, getResponseStatus(), getUrl());

} else if (isWebsocketCreated()) {
return format("%s [WEBSOCKET_CREATED] %s\n", prefix, getUrl());

} else if (isWebsocketRequest()) {
return format("%s [WEBSOCKET_REQUEST] %s\n", prefix, getPayloadData());

} else if (isWebsocketResponse()) {
return format("%s [WEBSOCKET_RESPONSE] %s\n", prefix, getPayloadData());
}

return super.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.selenium.core.webdriver.log;

/**
* This is POJO to extract message from web driver network log entry
*
* @author Dmytro Nochevnov
*/
public interface Message {
String getMethod();

void setMethod(String method);

Params getParams();

void setParams(Params params);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.selenium.core.webdriver.log;

/**
* This is POJO to extract 'params' value from web driver network log entry
*
* @author Dmytro Nochevnov
*/
public interface Params {
String getRequestId();

void setRequestId(String requestId);

String getUrl();

void setUrl(String url);

Request getRequest();

void setRequest(Request request);

Response getResponse();

void setResponse(Response request);

String getTimestamp();

void setTimestamp(String timestamp);
}
Loading