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

Selenium: Add ability to catch Chrome browser`s console logs #8502

Merged
merged 15 commits into from
Jan 31, 2018

Conversation

Ohrimenko1988
Copy link
Contributor

@Ohrimenko1988 Ohrimenko1988 commented Jan 29, 2018

What does this PR do?

Add ability to catch Chrome browser`s console logs

Output example:

2018-01-29 16:31:42,124[pool-1-thread-2]  [INFO ] [o.e.c.s.c.u.BrowserLogsUtil 61]      - SEVERE http://172.19.20.13:8080/api/keycloak/settings - Failed to load resource: the server responded with a status of 404 ()
2018-01-29 16:31:42,124[pool-1-thread-2]  [INFO ] [o.e.c.s.c.u.BrowserLogsUtil 61]      - SEVERE http://172.19.20.13:8080/che/workspace27javd 76:36 "Cannot load keycloak settings. This is normal for single-user mode."
2018-01-29 16:31:42,124[pool-1-thread-2]  [INFO ] [o.e.c.s.c.u.BrowserLogsUtil 61]      - SEVERE _app-0.js 17422 Failed to load resource: the server responded with a status of 404 ()

What issues does this PR fix or reference?

Issue: #8469

Release Notes

Docs PR

@benoitf benoitf added status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. kind/task Internal things, technical debt, and to-do tasks to be performed. labels Jan 29, 2018
*
* @return log messages from browser console
*/
public String getBrowserLogsAsString() {
Copy link
Contributor

Choose a reason for hiding this comment

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

AsString is redundant here

/** append browser logs to the test logs */
public void appendBrowserLogs() {
getBrowserLogs()
.forEach(logEntry -> LOG.info(format("%s %s", logEntry.getLevel(), logEntry.getMessage())));
Copy link
Contributor

Choose a reason for hiding this comment

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

LOG.info("{} {}", logEntry.getLevel(), logEntry.getMessage()) is more suitable.

@dmytro-ndp dmytro-ndp changed the title Selenium: Add ability to catch Chrome browser`s console logs [WIP] Selenium: Add ability to catch Chrome browser`s console logs Jan 29, 2018
* @return log messages from browser console
*/
public List<LogEntry> getBrowserLogs() {
return seleniumWebDriver.manage().logs().get(LogType.BROWSER).getAll();
Copy link
Contributor

@dmytro-ndp dmytro-ndp Jan 29, 2018

Choose a reason for hiding this comment

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

It should be synchronized with loggingPreferences.enable(LogType.BROWSER, Level.SEVERE); IMHO.
For example, we can use seleniumWebDriver.manage().logs().getAvailableLogTypes() to check presence of certain type in the logs.

Copy link
Contributor

@musienko-maxim musienko-maxim Jan 30, 2018

Choose a reason for hiding this comment

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

May be we add possible pass LogType into getBrowserLogs(). It may be very useful for investigation very specific cases? We can change signature of the method or overload exist.

}

public void open(TestWorkspace testWorkspace) throws Exception {
URL workspaceUrl = testWorkspaceUrlResolver.resolve(testWorkspace);
seleniumWebDriver.get(workspaceUrl.toString());
entrance.login(testWorkspace.getOwner());
try {
projectExplorer.waitProjectExplorer(60);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use timeout constant here.

}

public void open(TestWorkspace testWorkspace) throws Exception {
URL workspaceUrl = testWorkspaceUrlResolver.resolve(testWorkspace);
seleniumWebDriver.get(workspaceUrl.toString());
entrance.login(testWorkspace.getOwner());
try {
projectExplorer.waitProjectExplorer(60);
Copy link
Contributor

@dmytro-ndp dmytro-ndp Jan 29, 2018

Choose a reason for hiding this comment

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

Not every open(ws) requires waitProjectExplorer() just after it. For example, CheckoutToRemoteBranchTest.

Logs logs = seleniumWebDriver.manage().logs();
List<LogEntry> result = Collections.emptyList();

switch (logType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

All switch-case statement could be replaced by one command:
return logs.get(logType).getAll();

*/
public List<LogEntry> getLogs(String logType) {
Logs logs = seleniumWebDriver.manage().logs();
List<LogEntry> result = Collections.emptyList();
Copy link
Contributor

@dmytro-ndp dmytro-ndp Jan 31, 2018

Choose a reason for hiding this comment

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

result variable is redundant if we refactor code as mentioned here.

* @see LogType
* @return provided type of browser logs
*/
public List<LogEntry> getLogs(String logType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it doesn't make sense to allow selection of log type which is differ from "browser" if we enabling only LogType.BROWSER logging preference by command loggingPreferences.enable(LogType.BROWSER, Level.SEVERE); in class SeleniumWebDriver.

/**
* read and store browser logs to the test logs for change of logs level
*
* @see SeleniumWebDriver method "doCreateDriver"
Copy link
Contributor

Choose a reason for hiding this comment

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

Use {@link package.class#member label} notation to reference method in the docs.

* read and store browser logs to the test logs for change of logs level
*
* @see SeleniumWebDriver method "doCreateDriver"
* @see java.util.logging.Level
Copy link
Contributor

Choose a reason for hiding this comment

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

Use {@link package.class} notation to references class in the docs.

@dmytro-ndp dmytro-ndp changed the title [WIP] Selenium: Add ability to catch Chrome browser`s console logs Selenium: Add ability to catch Chrome browser`s console logs Jan 31, 2018
@Ohrimenko1988 Ohrimenko1988 merged commit 4baa9ea into master Jan 31, 2018
@Ohrimenko1988 Ohrimenko1988 deleted the selen-add-browser-logs branch January 31, 2018 13:46
@benoitf benoitf added this to the 6.0.0-M5 milestone Jan 31, 2018
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Jan 31, 2018
hkolvenbach pushed a commit to hkolvenbach/che that referenced this pull request Mar 2, 2018
…3613 to master

* commit 'd800fb816af6ed6f2d67702ac55ff5f8a8be3630': (34 commits)
  fixed version
  added new aws run script
  Prevents displaying installers with empty names and descriptions (eclipse-che#8536)
  adapt selenium tests according to changes with workspace config updating (eclipse-che#8561)
  Fix docs link. Dash instead underscore (eclipse-che#8548)
  fix aws
  ST-3613 custom keycloak image
  Dashboard: allow to update workspace config without workpace restarting (eclipse-che#8505)
  eclipse-che#8509 handle keybinding inside FileStructure Window (eclipse-che#8528)
  RELEASE: Set next development version (eclipse-che#8496)
  Add extra steps in the 'prepare()' to increase stability
  Renew URLs of CI servers to compare local selenium testing results (eclipse-che#8541)
  Selenium: Add ability to catch Chrome browser`s console logs (eclipse-che#8502)
  CHE-6923: Provide more space for committer fields in Preferences dialog. (eclipse-che#8480)
  Restore support of single-port Che mode (on docker infra)
  Factories links (eclipse-che#8530)
  CHE-7555 fix resolve factory flow
  Update policy of installers update (eclipse-che#8406)
  Improves debug panel, fixes UI of configure breakpoints popup (eclipse-che#8520)
  Update ProjectExplorerPresenter.java
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/task Internal things, technical debt, and to-do tasks to be performed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants