CSC/ECE 517 Spring 2016/Write automated tests for WebDriver
Write automated tests for the WebDriver server
ServoServo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in Rust language. It is currently developed on 64bit OS X, 64bit Linux, Android, and Gonk (Firefox OS). The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc.
Background information:
Python:
Python is a widely used high-level, general-purpose, interpreted, dynamic programming language. Python supports multiple programming paradigms, including object oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library. Modules for creating graphical user interfaces, connecting to relational databases, pseudorandom number generators, arithmetic with arbitrary precision decimals,[77] manipulating regular expressions, and doing unit testing are also included.
WebDriver:
The WebDriver specification defines a communication protocol for automating interactions with a web browser that would traditionally require a human being (eg. clicking the mouse on a particular link; typing text into an input field; etc.) This protocol is being implemented by major browsers such as Firefox, Edge, and Chrome, and Servo also provides a WebDriver server. The goal of this project is both to submit a broad range of automated client tests using the Python WebDriver API that can be run against multiple browsers, and also to report on how many of the tests Servo currently passes.
Scope
Initial Steps
- Compile Servo and ensure that it runs on
tests/html/about-mozilla.html
- To run a simple webdriver script using the python client against Servo.
- Create a
mach
command (test-webdriver
) inpython/servo/testing_commands.py
that will import each python file in the directory and execute thetest
method contained within it by invoking the Servo process before running each test, and killing it after each test finishes. - Create a
webdriver
directory undertests
where the forthcoming tests will reside. - Writing an automated test for loading a particular URL, asserting that the resulting page is the expected url.
Subsequent Steps
- Writing tests that exercise the lower-level command API (eg. self.send_command("POST", "url", body)) to test server capabilities:
- Writing a test with a simple get to a url that exists on the server, ensure that we get the right response type
- Sending a non-string as the URL and ensuring that we get the right kind of error message.
- Trying other kinds of non-conforming messages e.g. ones with extra fields (should be ignored) or no url field (should return the correct type of error)
- Testing that we are actually loading the correct page. This will require the use of some other webdriver functions e.g. to get an element's text, or take a screenshot
- Testing that Get always navigates the top level browsing context (by navigating to a page with an iframe, setting the current bc to that iframe, and ensuring that it is not just the iframe that is navigated).
- Trying Get with pages that return non-200 responses.
- Loading a page that loads slower than the timeout, and ensure we get the correct error message
Design pattern
Design patterns are not applicable as our task involved writing automated tests in python. However, the Implementation section below provides details of the steps the way it was implemented.
Implementation
The following steps were followed to meet the project requirements as per this github page.
Step 1:
We created a new mach
command (test-webdriver
) in python/servo/testing_commands.py
file. It imports each python file in the directory and executes the test
method contained within it.
Step 2:
We created tests in test.py and test1.py for loading a particular URL, asserting that the resulting page is the expected url.
Testing
Following are the steps to run the automated tests for WebDriver:
git clone https://github.com/krunal3103/servo
Note: Follow the steps listed in the Readme.md file of this link to clone and build servo on your local machine.
cd servo
./mach test-webdriver
You will see that all tests pass as expected.
Pull Request
Here is our pull request. In the link you can see all code snippets and commits as well as integration test progression information.