Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
feat(protractor): Browser.log() allows the actor to read the browser …
…log entries
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { stage } from '@integration/testing-tools'; | ||
import { containAtLeastOneItemThat, Ensure, includes, property } from '@serenity-js/assertions'; | ||
|
||
import { Browser, Navigate } from '../../../src'; | ||
import { pageFromTemplate } from '../../fixtures'; | ||
import { UIActors } from '../../UIActors'; | ||
|
||
describe('Browser', () => { | ||
|
||
const Bernie = stage(new UIActors()).actor('Bernie'); | ||
|
||
/** @test {Browser.log} */ | ||
it('allows the actor to read the browser log entries', () => Bernie.attemptsTo( | ||
Navigate.to(pageFromTemplate(` | ||
<html lang="en"> | ||
<body> | ||
<script> | ||
console.log('Hello from the console!'); | ||
</script> | ||
</body> | ||
</html> | ||
`)), | ||
|
||
Ensure.that(Browser.log(), containAtLeastOneItemThat(property('message', includes('Hello from the console!')))), | ||
)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Question } from '@serenity-js/core'; | ||
import { logging } from 'selenium-webdriver'; | ||
import { promiseOf } from '../../promiseOf'; | ||
import { BrowseTheWeb } from '../abilities'; | ||
|
||
export class Browser { | ||
|
||
/** | ||
* @desc | ||
* Creates a {@link Question} that reads the entries of the browser log | ||
* so that they can be asserted on. | ||
* | ||
* Please note that in order to ensure that the automated test has access to the browser log, | ||
* Protractor needs to be configured with the desired logging level, as per the example below. | ||
* | ||
* @example <caption>Enabling Protractor browser logging</caption> | ||
* // protractor.conf.js | ||
* exports.config = { | ||
* capabilities: { | ||
* loggingPrefs: { | ||
* // available options: OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL | ||
* browser: 'SEVERE' | ||
* }, | ||
* } | ||
* } | ||
* | ||
* @example <caption>Ensure the app didn't log anything to the console during the test</caption> | ||
* import { Actor, BrowseTheWeb, Browser } from '@serenity-js/core'; | ||
* import { Ensure, property, equals } from '@serenity-js/assertions'; | ||
* | ||
* actor.attemptsTo( | ||
* Ensure.that(Browser.log(), property('length', equals(0))), | ||
* ); | ||
* | ||
* @example <caption>Mark the test as "compromised" if the server responds with a 500 to any AJAX request during the test</caption> | ||
* import { Actor, BrowseTheWeb, Browser, TestCompromisedError } from '@serenity-js/core'; | ||
* import { Ensure, property, equals, not, contrainAtLeastOneItemThat } from '@serenity-js/assertions' | ||
* | ||
* actor.attemptsTo( | ||
* Ensure.that(Browser.log(), | ||
* not(contrainAtLeastOneItemThat( | ||
* property('message', includes('the server responded with a status of 500')) | ||
* )) | ||
* ).otherwiseFailWith(TestCompromisedError, 'The server is down'), | ||
* ); | ||
* | ||
* @see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#loggingpreferences-json-object | ||
* @returns {Question<Promise<logging.Entry[]>>} | ||
*/ | ||
static log() { | ||
return Question.about<Promise<logging.Entry[]>>(`browser log`, actor => | ||
promiseOf(BrowseTheWeb.as(actor).manage().logs().get('browser'))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters