Matt Thomas - Full Stack Developer
~2 years experience writing automated tests with Selenium
Testing the functionality of the web app to verify it does what it was meant to do.
We would like to test the application as the User would interact with it.
We will not be covering other kinds of tests. I.E.: Unit Testing
Often referred to as "Selenium Web Driver"
or "Standalone Selenium Server"
APIs for many languages
(PHP, Java, JavaScript (including Node.js), Ruby, Python C#)
Integrates with all modern browsers
Grid can be used to run many tests on numerous "servers" in parallel using different configurations
Documentation can be found on the Selenium website
http://www.seleniumhq.org/download/
The server is a Java Jar file, so it is cross platform by nature.
Move to an easily accessible location i.e.: ~/bin
Most Web Drivers are third party and are developed by the browser manufacturers.
They can be accessed via the Selenium Download page
Download to the same location as the Selenium server Jar file.
Requires Admin permissions to the computer to allow:
Registry key creation/edit using regedit
Set Internet Explorer security settings
Disable Enhanced Protected Mode
Also:
Must use Native Events
Have browser focus
Set zoom level set to 100%
IE WebDriver Documentation
java -Dwebdriver.chrome.driver=./chromedriver -jar selenium-server-standalone-3.4.0.jar
Various frameworks have abstracted the use in many languages
API support varies for each testing framework.
The API supports locating elements in various ways including:
The API supports interacting with the browser in the following ways:
Implements Acceptance, Functional & Unit tests
Integrates with Laravel, Zend (1 & 2), Symfony, Yii (1 & 2)
Built on top of PHPUnit
public function register(AcceptanceTester $I)
{
$I->wantTo('Register a new user ' . $this->email);
$I->amOnPage('/');
$I->see("Your Application's Landing Page.");
$I->click('Register');
$I->fillField('name', $this->name);
$I->fillField('email', $this->email);
$I->fillField('password', $this->password);
$I->fillField('password_confirmation', $this->password);
$I->click('button[type=submit]');
$I->see($this->name, 'a.dropdown-toggle');
}
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://localhost:8000')
driver.find_element_by_link_text('Login').click()
driver.find_element_by_name('email').send_keys("matsinet@gmail.com")
driver.find_element_by_name('password').send_keys("password")
driver.find_element_by_class_name('btn-primary').click()
driver.find_element_by_id('task-name').send_keys('Mocha task for STL Full Stack Meetup')
driver.find_element_by_class_name('btn-default').click()
driver.find_element_by_class_name('btn-danger').click()
driver.find_element_by_link_text('Matt Thomas').click()
driver.find_element_by_link_text('Logout').click()
driver.close()
Implements Acceptance, Functional & Unit tests
Integrates with Node.js, React, Angular
test = require('selenium-webdriver/testing'),
webdriver = require('selenium-webdriver');
test.describe('Create a task', function () {
test.it('should work', function () {
this.timeout(15000);
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('http://localhost:8000');
driver.findElement(webdriver.By.linkText("Login")).click();
driver.findElement(webdriver.By.name('email')).sendKeys('matsinet@gmail.com');
driver.findElement(webdriver.By.name('password')).sendKeys('password');
driver.findElement(webdriver.By.className("btn btn-primary")).click();
driver.findElement(webdriver.By.id('task-name')).sendKeys('Mocha task for STL Full Stack Meetup');
driver.findElement(webdriver.By.className("btn btn-default")).click();
driver.findElement(webdriver.By.className("btn btn-danger")).click();
driver.findElement(webdriver.By.linkText("Matt Thomas")).click();
driver.findElement(webdriver.By.linkText("Logout")).click();
driver.quit();
});
});
No Code Required!!! but does requires Firefox
Some knowledge of HTML/CSS and possibly XPath is helpful
Even though Selenium IDE has a "Save"feature that allows users to keep the tests in a table-based format for later import and execution, it is not designed to run your test passes nor is it designed to build all the automated tests you will need.
Selenium IDE is simply intended as a rapid prototyping tool.
Can also be played back using Selenium HTML Runner
It's not hard... unless you have to use IE :P
Install it and write your first test!
One step at a time, write small chucks and test, rinse and repeat
While writing your test, do the process manually, inspecting the DOM
If required, XPath is your best friend or your worth enemy.
All projects can use a limited set of acceptance tests, ok, maybe not APIs
Define a process for when and how your Acceptance tests should be run