Run GUI Test With Docker: Detect Web Page Loading Issues
How fast do your web pages load on the client side, especially the portal or login pages? And how do you detect unexpected 302, 404, or 5XX responses?
Join the DZone community and get the full member experience.Join For Free
how fast do your web pages load on the client side, especially the portal or login pages? and how do you detect unexpected 302, 404, or 5xx responses? it would probably hurt your user experience or even the functionalities. slow or problematic page loading is always bad .
good, if you have examined that carefully. and most likely, with multiple unpleasant manual steps. the thing is how can you be so sure that it's always good. even with the endless code changes.
to automate the gui test? you have to learn lots of gui automation skills, and the complicated setup. yes, i certainly believe you are capable of this, my friend. but you might not have enough time.
good news! with container technology, things are much easier now. check out this short post. and give it a try now!
why do we need to care about web page loading issues?
for good user experience  , we should limit the load speed of landing pages to within 0.5 to 2 seconds .
(tip: to test how fast your website loads from all over the world, use this free tool ).
unfortunately, we have lots of technical challenges.
not only is it hard to achieve fast loading speeds, but it's also difficult to detect the potential issues:
- the user experience may not the same among your visitors. driving you crazy, right?
- it's functionally working. and the slowness in the client network misleads you. consequently, you overlook the issues, which hurt your users every single visit.
- the list goes on...
as a serious it professional, you want to be on top of these issues. and when it happens, you want to be notified before anyone even notices. you want that, do you?
web browsers usually provide useful developer tools
browser-based developer tools can help us to diagnose these kinds of issues.
take chrome for example. with chrome devtools  , we can easily detect:
- how fast the web page loads (tip: remember to always clear the web browser cache. restarting web browsers may not be good enough since some browsers have filesystem caching).
- any 4xx or 5xx issues by checking network tab, like in the below screenshot.
but this is a manual way.
how can you automate this process? and what's better? if you automate, you'll get alerted if page loads start to take longer than before, or some new problematic network responses are captured.
at the first glance, i'm thinking about using recursive downloading with typical command lines, like wget or curl. or using network packets sniffer tools, like tcpdump for tcp layer or justniffer for the http layer  .
but they all turn out to be dead ends.
selenium turns out to be a good fit for gui automation
selenium will launch a web browser and perform the gui requests. 
once you get selenium and your web browser driver correctly setup, you can easily try the python code below.
from selenium import webdriver driver = webdriver.chrome() p = driver.get('http://dennyzhang.com/') # save screenshot fname = '/tmp/dennyzhang.png' driver.get_screenshot_as_file(fname) driver.close()
but the setup is tricky and dealing with selenium sdk takes time.
that's why i'm in favor of the docker way.
have fun with docker!
here, i've released one open docker image in docker hub and github .
it has everything you need to run a test against page loading:
- packages: selenium server, chrome driver, python sdk
- scripts: selenium_load_page.py , which runs the actual page loading tests.
how can i run a gui test on my local machines?
- step1: install the docker daemon to your machines. super easy with docker docs  , right?.
- step2: run the below commands to perform a hello world test case.
# start selenium docker container # docker stop selenium; docker rm selenium mkdir -p /tmp/screenshot && chmod 777 /tmp/screenshot docker run -d -p 4444:4444 -v /tmp/screenshot:/tmp/screenshot \ -h selenium --name selenium denny/selenium:v1 docker ps # wait for selenium service to be up and running sleep 5 # test page loading docker exec selenium python selenium_load_page.py \ --page_url "http://www.dennyzhang.com" # check generated screenshot ls -lth /tmp/screenshot # destroy selenium container, after testing docker stop selenium; docker rm selenium
selenium_load_page.py should be able to solve most of your problems.
please leave me comments, if i'm too proud of this script.
(note about login pages that require credentials. yes, these do need some work. prs or input are warmly welcomed).
## sample: ## - test page load: basic test ## python ./selenium_load_page.py --page_url http://www.dennyzhang.com ## ## - test page load: if it takes more than 5 seconds, fail the test. default timeout is 10 seconds ## python ./selenium_load_page.py --page_url http://www.dennyzhang.com --max_load_seconds 5 ## ## - test page load: after page loading, save screenshot ## python ./selenium_load_page.py --page_url http://www.dennyzhang.com --should_save_screenshot true
if you're a selenium ninja, you can definitely create your own test scripts. login to the docker container and do whatever your want.
please don't forget to share this post to your qa or devops colleagues, if you think it's helpful for your projects. thanks, my friend!
- linux measure process execution time, when already started
- avoid using same ssh private key for all your servers
check our popular posts? discuss with us on linkedin , twitter or newsletter .
Published at DZone with permission of Denny Zhang, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.