Skip to content

Commit

Permalink
Add sequential specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alister Scott committed Feb 10, 2020
1 parent b6723bc commit 2e1809d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -17,7 +17,8 @@
},
"devDependencies": {},
"scripts": {
"test": "./node_modules/.bin/mocha-parallel-tests --require babel-core/register specs"
"test": "./node_modules/.bin/mocha-parallel-tests --require babel-core/register specs",
"testseq": "./node_modules/.bin/mocha --require babel-core/register specs-seq"
},
"repository": {
"type": "git",
Expand Down
56 changes: 56 additions & 0 deletions specs-seq/demo-spec-seq.js
@@ -0,0 +1,56 @@
import playwright from 'playwright';
import config from 'config';
import assert from 'assert';

const mochaTimeoutMS = config.get( 'mochaTimeoutMS' );

describe( 'Playwright 1', function() {
this.timeout( mochaTimeoutMS );

let browser;

before( async function() {
browser = await playwright.chromium.launch();
} );

it( 'can wait for an element to appear', async function() {
const context = await browser.newContext();
const page = await context.newPage( `${ config.get( 'baseURL' )}` );
await page.waitFor( '#elementappearschild', { visible: true, timeout: 5000 } );
} );

it( 'can handle alerts', async function() {
const context = await browser.newContext();
const page = await context.newPage();
page.on('dialog', async dialog => {
await dialog.accept();
});
await page.goto( `${ config.get( 'baseURL' )}/leave` );
await page.click( '#homelink' );
await page.waitFor( '#elementappearsparent', { visible: true, timeout: 5000 } );
} );

it( 'can check for errors when there should be none', async function() {
const context = await browser.newContext();
const page = await context.newPage();
let errors = '';
page.on('pageerror', pageerr => {
errors = errors + pageerr;
});
await page.goto( `${ config.get( 'baseURL' )}` );
assert.equal( errors, '' );
} );

it( 'can use xpath selectors to find elements', async function() {
const context = await browser.newContext();
const page = await context.newPage();
await page.goto( `${ config.get( 'baseURL' )}` );
await page.waitFor( '//span[contains(., "Scissors")]' );
await page.click( '//span[contains(., "Scissors")]' );
await page.waitFor( '//div[contains(., "Scissors clicked!")]' );
} );

after( async function() {
await browser.close();
} );
} );

0 comments on commit 2e1809d

Please sign in to comment.