-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): Setup BDD and add first scenario
- Loading branch information
1 parent
c4f7475
commit 76bb143
Showing
17 changed files
with
644 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
test/screenshots | ||
.awcache/ | ||
node_modules | ||
npm-debug.log | ||
|
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,12 @@ | ||
var common = [ | ||
`--format ${ | ||
process.env.CI || !process.stdout.isTTY ? 'progress' : 'progress-bar' | ||
}`, | ||
'--parallel 20', | ||
'--require ./features/support/**/*.ts', | ||
'--require ./features/step_definitions/**/*.ts' | ||
].join(' '); | ||
|
||
module.exports = { | ||
default: common | ||
}; |
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,9 @@ | ||
Feature: Matching context | ||
In order to read relevant notice | ||
As a user | ||
I want to see notices that match my current tab context | ||
|
||
Scenario: Open Pixmania homepage | ||
When I open the url "https://pixmania.fr" | ||
Then I see the notification within 10 seconds | ||
And The first notice has text "Que choisir signale que de nombreux clients mécontents" |
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,16 @@ | ||
import { When } from 'cucumber'; | ||
import { BubbleWorld, InitializedBubbleWorld } from '../support/setup'; | ||
import expect from 'expect'; | ||
|
||
When(/^I open the url "(.+)"$/, async function(this: BubbleWorld, url: string) { | ||
let error = null; | ||
try { | ||
await (this as InitializedBubbleWorld).page.goto(url, { | ||
waitUntil: 'networkidle0' | ||
}); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeNull(); | ||
}); |
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,34 @@ | ||
import { Then } from 'cucumber'; | ||
import { BubbleWorld, InitializedBubbleWorld } from '../support/setup'; | ||
import expect from 'expect'; | ||
import { findIframe } from '../support/iframe'; | ||
|
||
Then(/^The first notice has text "(.+)"$/, async function( | ||
this: BubbleWorld, | ||
text: string | ||
) { | ||
let error = null; | ||
try { | ||
const frame = findIframe((this as InitializedBubbleWorld).page); | ||
expect(frame).toBeDefined(); | ||
|
||
if (frame) { | ||
const firstNoticeP = await frame.$( | ||
"article p[data-test-type='noticeTitle']" | ||
); | ||
expect(firstNoticeP).toBeDefined(); | ||
|
||
if (firstNoticeP) { | ||
const firstNoticeText = await frame.evaluate( | ||
e => e.textContent, | ||
firstNoticeP | ||
); | ||
expect(firstNoticeText).toMatch(new RegExp(`^${text}`)); | ||
} | ||
} | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeNull(); | ||
}); |
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,27 @@ | ||
import { Then } from 'cucumber'; | ||
import { BubbleWorld, InitializedBubbleWorld } from '../support/setup'; | ||
import expect from 'expect'; | ||
import { findIframe } from '../support/iframe'; | ||
|
||
Then(/^I see the notification within (\d+) seconds$/, async function( | ||
this: BubbleWorld, | ||
delay: number | ||
) { | ||
let error = null; | ||
try { | ||
const frame = findIframe((this as InitializedBubbleWorld).page); | ||
expect(frame).toBeDefined(); | ||
|
||
if (frame) { | ||
await frame.waitForSelector( | ||
`section[data-test-id="bubble-notification"]`, | ||
{ timeout: delay * 1000 } | ||
); | ||
} | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeNull(); | ||
}); | ||
// document.querySelectorAll('body section[data-test-id="bubble-notification"]'); |
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,7 @@ | ||
import { Page } from 'puppeteer'; | ||
|
||
export const findIframe = (page: Page) => | ||
page | ||
.mainFrame() | ||
.childFrames() | ||
.find(frame => frame.name() === 'BubbleIONotification'); |
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,51 @@ | ||
import { After, Before, Status, setDefaultTimeout, World } from 'cucumber'; | ||
import puppeteer, { Browser, Page } from 'puppeteer'; | ||
import path from 'path'; | ||
|
||
setDefaultTimeout(60 * 1000); | ||
|
||
const CRX_PATH = path.resolve(process.cwd(), 'build', 'dev'); | ||
|
||
const config = { | ||
screenshotPath: path.resolve(process.cwd(), 'test', 'screenshots') | ||
}; | ||
|
||
export interface BubbleWorld extends World { | ||
browser?: Browser; | ||
page?: Page; | ||
} | ||
|
||
export interface InitializedBubbleWorld extends BubbleWorld { | ||
browser: Browser; | ||
page: Page; | ||
} | ||
|
||
Before(async function(this: BubbleWorld) { | ||
this.browser = await puppeteer.launch({ | ||
headless: false, | ||
args: [ | ||
'--no-sandbox', | ||
'--disable-dev-shm-usage', | ||
`--disable-extensions-except=${CRX_PATH}`, | ||
`--load-extension=${CRX_PATH}` | ||
], | ||
ignoreHTTPSErrors: true | ||
}); | ||
const background = await this.browser.newPage(); | ||
await background.goto( | ||
'chrome-extension://iddjnlppdcfkhliebhkhbidlhemoncon/background.html', | ||
{ waitUntil: 'networkidle0' } | ||
); | ||
|
||
this.page = await this.browser.newPage(); | ||
await background.close(); | ||
}); | ||
|
||
After(async function(this: BubbleWorld, scenario) { | ||
if (scenario.result.status === Status.FAILED && this.page) { | ||
const screenShotName = scenario.pickle.name.replace(/[\W_]+/g, '-'); | ||
await this.page.screenshot({ | ||
path: `${config.screenshotPath}/error/${screenShotName}.png` | ||
}); | ||
} | ||
}); |
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
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
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
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
Oops, something went wrong.