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 22 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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.eclipse.che.ide.util.input.CharCodeWithModifiers;
import org.eclipse.che.ide.util.input.SignalEvent;
import org.eclipse.che.ide.util.input.SignalEventUtils;
import org.eclipse.che.ide.util.loging.Log;

/**
* Implementation of {@link FileStructure} view.
Expand Down Expand Up @@ -112,6 +113,7 @@ public FileStructureImpl(
/** {@inheritDoc} */
@Override
public void setStructure(CompilationUnit compilationUnit, boolean showInheritedMembers) {
Log.info(getClass(), compilationUnit.toString());
showInheritedLabel.setText(
showInheritedMembers
? locale.hideInheritedMembersLabel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,23 @@ public void show(EditorPartPresenter editorPartPresenter) {
}

final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);

Log.info(
getClass(), "Going to take information for " + fqn + " at " + System.currentTimeMillis());
javaNavigationService
.getCompilationUnit(project.get().getLocation(), fqn, showInheritedMembers)
.then(
unit -> {
Log.info(
getClass(),
">>>>> Got information for " + fqn + " at " + System.currentTimeMillis());
view.setTitleCaption(editorPartPresenter.getEditorInput().getFile().getName());
view.setStructure(unit, showInheritedMembers);
view.showDialog();
showInheritedMembers = !showInheritedMembers;
Log.info(
getClass(),
">>>>> Shown information for " + fqn + " at " + System.currentTimeMillis());
})
.catchError(
arg -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public Promise<CompilationUnit> getCompilationUnit(
return requestFactory
.createGetRequest(url)
.header(ACCEPT, APPLICATION_JSON)
.loader(loaderFactory.newLoader("Getting information about ..."))
.loader(loaderFactory.newLoader("Getting information about " + fqn))
.send(unmarshallerFactory.newUnmarshaller(CompilationUnit.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import org.eclipse.che.plugin.java.server.rest.CodeAssistService;
import org.eclipse.che.plugin.java.server.rest.CompilerSetupService;
import org.eclipse.che.plugin.java.server.rest.JavaFormatterService;
import org.eclipse.che.plugin.java.server.rest.JavaModelExceptionMapper;
import org.eclipse.che.plugin.java.server.rest.JavaNavigationService;
import org.eclipse.che.plugin.java.server.rest.JavaReconcileService;
import org.eclipse.che.plugin.java.server.rest.JavadocService;
import org.eclipse.che.plugin.java.server.rest.JavadocUrlProviderImpl;
import org.eclipse.che.plugin.java.server.rest.JdtExceptionMapper;
import org.eclipse.che.plugin.java.server.rest.RefactoringExceptionMapper;
import org.eclipse.che.plugin.java.server.rest.RefactoringService;
import org.eclipse.che.plugin.java.server.rest.SearchJsonRpcService;
import org.eclipse.core.internal.filebuffers.FileBuffersPlugin;
Expand All @@ -47,6 +49,8 @@ protected void configure() {
bind(CodeAssistService.class);
bind(JavaFormatterService.class);
bind(JdtExceptionMapper.class);
bind(JavaModelExceptionMapper.class);
bind(RefactoringExceptionMapper.class);
bind(CompilerSetupService.class);
bind(ResourcesPlugin.class).asEagerSingleton();
bind(JavaPlugin.class).asEagerSingleton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
*/
package org.eclipse.che.plugin.java.server.refactoring;

import org.eclipse.che.api.core.ServerException;

/**
* Throws when we can't perform refactoring
*
* @author Evgen Vidolob
*/
public class RefactoringException extends Exception {
public class RefactoringException extends ServerException {

public RefactoringException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.plugin.java.server.rest;

import javax.inject.Singleton;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.eclipse.che.api.core.rest.shared.dto.ServiceError;
import org.eclipse.che.dto.server.DtoFactory;
import org.eclipse.jdt.core.JavaModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Exception mapper for all JDT exceptions
*
* @author Evgen Vidolob
*/
@Provider
@Singleton
public class JavaModelExceptionMapper implements ExceptionMapper<JavaModelException> {

private static final Logger LOG = LoggerFactory.getLogger(JavaModelExceptionMapper.class);

@Override
public Response toResponse(JavaModelException exception) {
LOG.error(exception.getMessage());
ServiceError serviceError =
DtoFactory.getInstance().createDto(ServiceError.class).withMessage(exception.getMessage());
return Response.status(Response.Status.BAD_REQUEST)
.entity(DtoFactory.getInstance().toJson(serviceError))
.type(MediaType.APPLICATION_JSON)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.plugin.java.server.rest;

import javax.inject.Singleton;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.eclipse.che.dto.server.DtoFactory;
import org.eclipse.che.plugin.java.server.refactoring.RefactoringException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Exception mapper for all JDT exceptions
*
* @author Evgen Vidolob
*/
@Provider
@Singleton
public class RefactoringExceptionMapper implements ExceptionMapper<RefactoringException> {

private static final Logger LOG = LoggerFactory.getLogger(RefactoringExceptionMapper.class);

@Override
public Response toResponse(RefactoringException exception) {
LOG.error(exception.getMessage());
return Response.status(Response.Status.BAD_REQUEST)
.entity(DtoFactory.getInstance().toJson(exception.getServiceError()))
.type(MediaType.APPLICATION_JSON)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.eclipse.jdt.internal.core.JavaModel;
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Service for all Java refactorings
Expand All @@ -58,6 +60,7 @@
public class RefactoringService {
private static final JavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
private RefactoringManager manager;
private static final Logger LOG = LoggerFactory.getLogger(RefactoringService.class);

@Inject
public RefactoringService(RefactoringManager manager) {
Expand All @@ -78,6 +81,11 @@ public RefactoringService(RefactoringManager manager) {
@Produces("text/plain")
public String createMoveRefactoring(CreateMoveRefactoring cmr)
throws JavaModelException, RefactoringException {
LOG.info(
"createMoveRefactoring started in "
+ System.currentTimeMillis()
+ " ms with "
+ cmr.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Use please LOG.info("createMoveRefactoring started in {} " ms with " {}", System.currentTimeMillis(), cmr.toString())

IJavaProject javaProject = model.getJavaProject(cmr.getProjectPath());
IJavaElement[] javaElements;
try {
Expand All @@ -104,16 +112,30 @@ public String createMoveRefactoring(CreateMoveRefactoring cmr)
javaElements = cmr.getElements().stream().map(map).toArray(IJavaElement[]::new);

} catch (IllegalArgumentException e) {
LOG.error(
"createMoveRefactoring fail in "
+ System.currentTimeMillis()
+ " ms with exception "
+ e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

if (e.getCause() instanceof JavaModelException) {
throw (JavaModelException) e.getCause();
} else {
throw e;
}
}
if (RefactoringAvailabilityTester.isMoveAvailable(new IResource[0], javaElements)) {
return manager.createMoveRefactoringSession(javaElements);
String moveRefactoringSession = manager.createMoveRefactoringSession(javaElements);
LOG.info(
"createMoveRefactoring finished in "
+ System.currentTimeMillis()
+ " ms with session id "
+ moveRefactoringSession);
return moveRefactoringSession;
Copy link
Contributor

Choose a reason for hiding this comment

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

}

LOG.error(
"createMoveRefactoring finished in "
+ System.currentTimeMillis()
+ " ms with with RefactoringException");
Copy link
Contributor

Choose a reason for hiding this comment

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

throw new RefactoringException("Can't create move refactoring.");
}

Expand Down Expand Up @@ -238,6 +260,11 @@ public RefactoringResult applyRefactoring(RefactoringSession session)
@Consumes("application/json")
public RenameRefactoringSession createRenameRefactoring(CreateRenameRefactoring settings)
throws CoreException, RefactoringException {
LOG.info(
"createRenameRefactoring started in "
+ System.currentTimeMillis()
+ " ms with "
+ settings.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

IJavaProject javaProject = model.getJavaProject(settings.getProjectPath());
IJavaElement elementToRename;
ICompilationUnit cu = null;
Expand All @@ -257,11 +284,22 @@ public RenameRefactoringSession createRenameRefactoring(CreateRenameRefactoring
elementToRename = null;
}
if (elementToRename == null) {
LOG.error(
"createRenameRefactoring fail in "
+ System.currentTimeMillis()
+ " ms with RefactoringException: Can't find java element to rename. ");
Copy link
Contributor

Choose a reason for hiding this comment

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

throw new RefactoringException("Can't find java element to rename.");
}

return manager.createRenameRefactoring(
elementToRename, cu, settings.getOffset(), settings.isRefactorLightweight());
RenameRefactoringSession renameRefactoring =
manager.createRenameRefactoring(
elementToRename, cu, settings.getOffset(), settings.isRefactorLightweight());
LOG.info(
"createRenameRefactoring finished in "
+ System.currentTimeMillis()
+ " ms with "
+ renameRefactoring.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

return renameRefactoring;
}

/**
Expand Down
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
Loading