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

Testing: Experiment with Puppeteer for E2E testing #5618

Merged
merged 16 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
E2E tests: move the hello gutenberg cypress test
  • Loading branch information
youknowriad committed Mar 21, 2018
commit e7300e085a5fe0de26a6d4bfc9a1b4096a646974
61 changes: 6 additions & 55 deletions test/e2e/specs/a11y.test.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,13 @@
/* eslint-env jest */
/* global page, browser */
/* global page */

const path = require( 'path' );
const url = require( 'url' );
const puppeteer = require( 'puppeteer' );

// Config

const BASE_URL = 'http:https://localhost:8888';
const USERNAME = 'admin';
const PASSWORD = 'password';

// Global Setup

beforeAll( async () => {
global.browser = await puppeteer.launch();
global.page = await browser.newPage();
} );

afterAll( async () => {
await browser.close();
} );

// Utilities

function getUrl( urlPath ) {
return path.join( BASE_URL, urlPath );
}

function getCurrentPathName() {
return url.parse( page.url() ).pathname;
}

async function login() {
if ( getCurrentPathName() !== '/wp-login.php' ) {
await page.goto( getUrl( 'wp-login.php' ) );
}

await page.type( '#user_login', USERNAME );
await page.type( '#user_pass', PASSWORD );
await page.click( '#wp-submit' );
return page.waitForNavigation();
}

async function visitAdmin( adminPath ) {
await page.goto( path.join( BASE_URL, 'wp-admin', adminPath ) );
if ( getCurrentPathName() === '/wp-login.php' ) {
await login();
return visitAdmin( adminPath );
}
}

async function newPost() {
await visitAdmin( 'post-new.php' );
}
/**
* Internal dependencies
*/
import './support/bootstrap';
import { newPost } from './support';

// Tests
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know that these specific comments add much value.


describe( 'a11y', () => {
beforeAll( async () => {
await newPost();
Expand Down
34 changes: 34 additions & 0 deletions test/e2e/specs/hello.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-env jest */
/* global page */

/**
* Internal dependencies
*/
import './support/bootstrap';
import { newPost, visitAdmin } from './support';

// Tests
describe( 'hello', () => {
beforeAll( async () => {
await newPost();
} );

it( 'Should show the New Post Page in Gutenberg', async () => {
expect( page.url() ).toEqual( expect.stringContaining( 'post-new.php' ) );
const title = await page.$( '[placeholder="Add title"]' );
expect( title ).not.toBeNull();
} );

it( 'Should have no history', async () => {
const undoButton = await page.$( '.editor-history__undo:not( :disabled )' );
const redoButton = await page.$( '.editor-history__redo:not( :disabled )' );

expect( undoButton ).toBeNull();
expect( redoButton ).toBeNull();
} );

it( 'Should not prompt to confirm unsaved changes', async () => {
await visitAdmin( 'edit.php' );
expect( page.url() ).not.toEqual( expect.stringContaining( 'post-new.php' ) );
} );
} );
12 changes: 12 additions & 0 deletions test/e2e/specs/support/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-env jest */
/* global browser */
import puppeteer from 'puppeteer';

beforeAll( async () => {
global.browser = await puppeteer.launch( { headless: false } );
global.page = await browser.newPage();
} );

afterAll( async () => {
await browser.close();
} );
39 changes: 39 additions & 0 deletions test/e2e/specs/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* global page */
import path from 'path';
import url from 'url';

// Config
const BASE_URL = 'http:https://localhost:8888';
const USERNAME = 'admin';
const PASSWORD = 'password';

function getUrl( urlPath ) {
return path.join( BASE_URL, urlPath );
}

function getCurrentPathName() {
return url.parse( page.url() ).pathname;
}

async function login() {
if ( getCurrentPathName() !== '/wp-login.php' ) {
await page.goto( getUrl( 'wp-login.php' ) );
}

await page.type( '#user_login', USERNAME );
await page.type( '#user_pass', PASSWORD );
await page.click( '#wp-submit' );
return page.waitForNavigation();
}

export async function visitAdmin( adminPath ) {
await page.goto( path.join( BASE_URL, 'wp-admin', adminPath ) );
if ( getCurrentPathName() === '/wp-login.php' ) {
await login();
return visitAdmin( adminPath );
}
}

export async function newPost() {
await visitAdmin( 'post-new.php' );
}