Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Ui testing with splinter - Fri, 30 May 2014
1. UI Testing with Splinter
Taizo Ito <taizo.ito@hde.co.jp>
HDE, Inc.
2. What’s Splinter?
UI Testing tool for web applications
- Open source software (BSD-like License)
- Implemented by Python
As of this writing, there seems to be no other python-implemented tools like this.
- It helps you control actions on web browser
3. Features
- Easy to install/setup
- Support popular browsers
- Easy to use
Simple and intuitive API
4. Installation
Simply run the following command. That’s all!
$ sudo pip install splinter
As an additional requirement, a web client such as
Chrome, Firefox and PhantomJS must be installed.
5. Supported Browsers
Splinter provides multiple web drivers:
Browser based
Chrome, Firefox, (Remote)
Headless
PhantomJS, zope.testbrowser, django client, Flask client
Remote
Uses Selenium RC to automate browser actions on a remote machine such as
Sauce Labs.
6. Web
Driver
Splinter is an abstraction layer
The same test code covers actions of any browser
A
P
I
Browser-based
Selenium
Headless
PhantomJS
zope.testbrowser
Chrome
Firefox
RemoteTest
Code
Remote
Webdriver Server
Sauce Labs (IE)
HTTP
Splinter
7. APIs
Each method is so intuitive; It’s easy to use.
- visit()
Go to the specified URL. e.g. browser.visit(‘http://www.hde.co.jp’) # then you can see html text from
browser.html.
- fill()
Fill an input form with the specified text. e.g. browser.find_by_id(‘your_name’).fill(‘taizo’)
- click()
Click an element such as button or link text. e.g. browser.find_by_id(‘search_button’).click()
and more…
8. Example: Login with Single Sign On(1)
Login to App using Google Apps Federated Login
1 browser = Browser(“phantomjs”)
2
3 browser.visit(“https://foobar.example.com/login”)
4
5 browser.find_by_id(“Email”).fill(“foobar@example.com”)
6 browser.find_by_id(“Passwd”).fill(“secret_password”)
7 browser.find_by_id(“signIn”).click()
8 time.sleep(1)
9
10 if browser.title == “Request for Permission”:
11 browser.find_by_id(“submit_approve_access”).click()
12 time.sleep(1)
13
14 assert browser.title == “This is a title of App”, “Failed to login”
9. Example: Login with Single Sign On(2)
Login to App using Microsoft WAAD SAML
1 browser = Browser(“phantomjs”)
2
3 browser.visit(“https://foobar.example.com/login”)
4
5 browser.find_by_id(“cred_userid_inputtext”).fill(“foobar@example.com”)
6 browser.find_by_id(“cred_password_inputtext”).fill(“secret_password”)
7 browser.find_by_id(“cred_keep_me_signed_in_checkbox”).check()
8 time.sleep(1)
9 browser.find_by_id(“cred_sign_in_button”).click()
10 time.sleep(1)
11
12 assert browser.title == “This is a title of App”, “Failed to login”
11. Features not implemented
We are not allowed to:
- Get contents of downloaded data by using Splinter.
We have to use requests module to get it instead of Splinter.
- Customize HTTP Request headers when using headless web driver.
Therefore, we can’t check if the multi-language feature of web apps works well.
Accept-Language: en-US,en;q=0.8,ja;q=0.6
12. Tips
- Use Google Chrome’s Developer Console to get the
XPath of an element.
It is easy to identify the element using find_by_xpath().
- To customize HTTP Request headers in PhantomJS
driver,
get the latest vesion from Github, which supports custom headers.
My PR was accepted ;-) https://github.com/cobrateam/splinter/pull/316
- Use Splinter with behave. http://pythonhosted.org/behave/
You can easily practice BDD(Behavior-Driven Development) for web apps with Python.