Skip to content

Instantly share code, notes, and snippets.

View joelgriffith's full-sized avatar
💻
Turns out I'm really good at computers

Joel Griffith joelgriffith

💻
Turns out I'm really good at computers
View GitHub Profile
@joelgriffith
joelgriffith / goto.js
Last active July 11, 2017 16:36
Launching Navalia
const { Chrome } = require('navalia');
const chrome = new Chrome();
chrome.goto('https://www.google.com')
.then(() => chrome.done());
@joelgriffith
joelgriffith / click.js
Created July 8, 2017 20:25
Navalia goto then click
const { Chrome } = require('navalia');
const chrome = new Chrome();
async function interactWithSearch() {
await chrome.goto('https://joelgriffith.github.io/navalia/');
await chrome.focus('#search-input');
await chrome.type('#search-input', 'coverage');
return chrome.done();
}
interactWithSearch();
@joelgriffith
joelgriffith / navalia-coverage.js
Last active July 8, 2017 20:38
Coverage on Navalia Docs
const { Chrome } = require('navalia');
const chrome = new Chrome();
async function checkCoverageOnPage() {
// Note that we've set `coverage: true` as a 2nd parameter, this will instrument Chrome appropriately
await chrome.goto('https://joelgriffith.github.io/navalia/', { coverage: true });
await chrome.focus('#search-input');
await chrome.type('#search-input', 'coverage');
const stats = await chrome.coverage('https://www.google-analytics.com/analytics.js');
@joelgriffith
joelgriffith / Login-Page.js
Created July 11, 2017 16:48
Simple React login-page for testing
import React, { Component } from 'react';
import './App.css';
class LoginPage extends Component {
constructor() {
super();
this.state = {
username: '',
password: '',
error: '',
@joelgriffith
joelgriffith / react.spec.js
Last active July 11, 2017 16:58
Setup of Navalia E2E Test
const { Chrome } = require('navalia');
const pageUrl = 'http://localhost:3000/';
describe('My Page', () => {
let chrome = {};
// Setup a clean instance for each test
beforeEach(() => {
chrome = new Chrome();
});
@joelgriffith
joelgriffith / empty-username.js
Created July 11, 2017 17:07
Blank username assertion
// Goto a page, click a button, expect a message
it('should show an error if no username is filled out', () => {
return chrome.goto('http://localhost:3000/')
.then(() => chrome.click('[data-test="submit"]'))
.then(() => chrome.html('[data-test="error"]'))
.then((html) => expect(html).toContain('Username is required'));
});
@joelgriffith
joelgriffith / composoable-login.js
Created July 11, 2017 17:20
Abstracting User Interactions in Navalia
// :missingUsername visits a page and immediately clicks submit
// without entering the user's name. It returns the chrome instance
// so you can invoke further actions or assertions!
const missingUsername = (chrome) =>
chrome.goto('http://localhost:3000/')
.then(() => chrome.click('[data-test="submit"]'));
@joelgriffith
joelgriffith / composable-test.js
Created July 11, 2017 17:24
Composing a user interaction with further assertions
// :missingUsername visits a page and immediately clicks submit
// without entering the user's name. It returns the chrome instance
// so you can invoke further actions or assertions!
const missingUsername = (chrome) =>
chrome.goto('http://localhost:3000/')
.then(() => chrome.click('[data-test="submit"]'));
// Consume the prior action and assert further behavior
it('should allow users to dismiss errors', () => {
return missingUsername(chrome)
@joelgriffith
joelgriffith / full-suite-chrome.js
Last active July 11, 2017 17:38
Full test suite with just Chrome
const { Chrome } = require('navalia');
describe('My Page', () => {
let chrome = {};
beforeEach(() => {
chrome = new Chrome();
});
afterEach(() => {
@joelgriffith
joelgriffith / empty-username-navalia.js
Created July 11, 2017 17:55
Validating username error with Navalia LB
// Register the work against a Navalia instance
// returning so the test can signal completetion:
it('should have a username input', () => {
return navalia.run((chrome) => chrome.goto('http://localhost:3000/')
.then(() => chrome.exists('[data-test="username"]'))
.then((exists) => expect(exists).toEqual(true)));
});