- Install WebDriver and ChromeDriver, and get access to them in test code
- Spin up a web browser pointing to the system
- Use locators to assert on expected page text
- Use locators to navigate to a new page
- Use locators to fill form values
- Use locators to submit a form
- Write test cases for happy-path functionality
Same pattern as previous pracs
- Commit any outstanding changes on your Prac02 branch:
git commit -am 'Some message'
- Head back over to master:
git checkout master
- Check out the Start Point for Prac 3:
git checkout Prac06-StartPoint
- Create a branch to make your changes on without impacting the main repo:
git checkout -b Prac06
- Add
selenium-webdriver
andchromedriver
as dev dependencies - Create a new
automated-ui
folder - Create new
package.json
andlaunch.json
entry points for our UI tests - Create a new test file for our UI tests
- Add a reference to our app to ensure it gets spun up
- Get access to
chromedriver
andselenium-webdriver
in your test file - Get a reference to webdriver's
By
anduntil
utilities - Ensure your tests start a Chrome instance and navigate to the app homepage before they run
- Add a new test that asserts the homepage has today's date on it
- Add another test that navigates to the Random page and requests a random pet match, and asserts that the correct text is displayed
Here's a step-by-step walkthrough of the practical steps, for if you get stuck :)
- Add
selenium-webdriver
andchromedriver
as dev dependenciesnpm install selenium-webdriver --save-dev
npm install chromedriver --save-dev
- Create a new
automated-ui
folder- New folder
test/automated-ui
- New folder
- Create new
package.json
andlaunch.json
entry points for our UI tests- Follow equivalent steps from the Integration Testing prac for details
- Create a new test file for our UI tests
- New file
test/automated-ui/browser-tests.js
- New file
- Add a reference to our app to ensure it gets spun up
var app = require('../../app');
- Get access to
chromedriver
andselenium-webdriver
in your test filevar chromedriver = require('chromedriver');
var webdriver = require('selenium-webdriver');
- Get a reference to webdriver's
By
anduntil
utilitiesvar by = webdriver.By;
var until = webdriver.until;
- Ensure your tests start a Chrome instance and navigate to the app homepage before they run
var driver; before("Start Chrome and navigate to homepage", function() { driver = new webdriver.Builder() .forBrowser('chrome') .build(); return driver.get("http://localhost:4000/"); });
- Add a new test that asserts the homepage has today's date on it
describe("Spinning up our app", function() { it("should be greeted with today's date", function() { return driver.findElement(by.id("todaysDate")) .then((element) => element.getText()) .then((dateText) => dateText.should.equal(new Date().toDateString())); }); });
- Add another test that navigates to the Random page and requests a random pet match
describe("Randomiser", function() { describe("when randomly matching a pet", function() { beforeEach(function() { return driver.findElement(by.name("random")) .then(m => m.click()) .then(() => driver.findElement(by.tagName("button"))) .then(button => button.click()) .then(() => driver.findElement(by.name("petInfo"))) .then(petInfo => driver.wait(until.elementIsVisible(petInfo))) }); it("should find a match", function() { return driver.findElement(by.name("matchResult")) .then(mr => driver.wait(until.elementIsVisible(mr))) .then(mr => mr.getText()) .then(mrText => mrText.should.contain("Your perfect pet is a")); }); }); });
- Write tests for the MatchMaker functionality
- Write tests for the History functionality