Skip to content

Commit

Permalink
[plguin-web-app] Add support of INFO level for the browser console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ikalinin1 committed Aug 24, 2022
1 parent b17c2ca commit f8bbfa5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
19 changes: 18 additions & 1 deletion docs/modules/plugins/pages/plugin-web-app.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,24 @@ Then `${response}` matcher `.+`

This set of steps allows to validate the https://developer.mozilla.org/en-US/docs/Web/API/console[browser console logging messages].

:log-levels: List of the comma-separated messages levels. The supported levels are: ERRORS, WARNINGS.
:log-levels: List of the comma-separated messages levels. The supported levels are: ERRORS, WARNINGS, INFOS.

[TIP]
=====
In order to configure availability of the INFO level messages use following properties:
[cols="1,2"]
|===
|Browser
|Property to enable INFO logs
|Google Chrome
|`selenium.capabilities.goog\:loggingPrefs.browser=INFO`
|Microsoft Edge Chromium
|]selenium.capabilities.ms\:loggingPrefs.browser=INFO`
|===
=====

==== Validate log entries absence

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,8 @@
public enum BrowserLogLevel
{
ERRORS(Level.SEVERE),
WARNINGS(Level.WARNING);
WARNINGS(Level.WARNING),
INFOS(Level.INFO);

private final Level level;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class JsValidationSteps
* is enabled).</p>
* <p>Step passes if console logs were found, otherwise it fails. All found logs are available in
* report step's attachment</p>
* @param logEntries Log entries to check: "errors", "warnings", "errors, warnings" or "warnings, errors"
* @param logEntries Comma-separated list of entries to check. Possible values: "errors", "warnings", "infos".
* @param regex Regular expression to filter log entries
*/
@Then("there are browser console $logEntries by regex `$regex`")
Expand All @@ -68,7 +68,7 @@ public void checkThereAreLogEntriesOnOpenedPageFilteredByRegExp(List<BrowserLogL
* is enabled).</p>
* <p>Step passes if no errors were found, otherwise it fails. All found errors are available in
* report step's attachment</p>
* @param logEntries Log entries to check: "errors", "warnings", "errors, warnings" or "warnings, errors"
* @param logEntries Comma-separated list of entries to check. Possible values: "errors", "warnings", "infos".
*/
@Then("there are no browser console $logEntries")
public void checkJsLogEntriesOnOpenedPage(List<BrowserLogLevel> logEntries)
Expand All @@ -85,7 +85,7 @@ public void checkJsLogEntriesOnOpenedPage(List<BrowserLogLevel> logEntries)
* is enabled).</p>
* <p>Step passes if no errors were found, otherwise it fails. All found errors are available in
* report step's attachment</p>
* @param logEntries Log entries to check: "errors", "warnings", "errors, warnings" or "warnings, errors"
* @param logEntries Comma-separated list of entries to check. Possible values: "errors", "warnings", "infos".
* @param regex Regular expression to filter log entries
*/
@Then(value = "there are no browser console $logEntries by regex '$regex'", priority = 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.vividus.selenium.logging;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.logging.Level;
import java.util.stream.Stream;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class BrowserLogLevelTests
{
static Stream<Arguments> levels()
{
return Stream.of(Arguments.of(BrowserLogLevel.ERRORS, Level.SEVERE),
Arguments.of(BrowserLogLevel.WARNINGS, Level.WARNING),
Arguments.of(BrowserLogLevel.INFOS, Level.INFO));
}

@ParameterizedTest
@MethodSource("levels")
void shouldMapLevels(BrowserLogLevel browserLogLevel, Level level)
{
assertEquals(level, browserLogLevel.getLevel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ engine.alias-paths=aliases/test-aliases.json

ui.locator.image.locator-type=xpath
ui.locator.image.pattern=//img[@name='%s' and @alt = '%s']

selenium.capabilities.goog\:loggingPrefs.browser=INFO
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ When I execute javascript `console.error('error')` with arguments:
Then there are browser console ERRORS by regex `.*error.*`
When I execute javascript `console.warn('warninig')` with arguments:
Then there are browser console WARNINGS by regex `.*warninig.*`
When I execute javascript `console.log('info')` with arguments:
Then there are browser console INFOS by regex `.*info.*`


Scenario: Verify step: Then there are no browser console $logEntries
When I execute javascript `console.warn('warninig')` with arguments:
Then there are no browser console INFOS
Then there are no browser console ERRORS


Expand Down

0 comments on commit f8bbfa5

Please sign in to comment.