In web testing, one of the unavoidable tests is browser compatibility testing, where we always have to install n browsers on one or more machines without automated testing, and then manually verify the main business process and key function module functions on different browsers to detect different browsers or versions of the browser. Whether our web app works properly.
Let's take a look at how to automate cross-browser testing using Python selenium.
What is cross-browser testing
Cross-browser testing is a branch of functional testing to verify that Web apps work correctly on different browsers.
Why cross-browser testing is required
Typically, we expect web-class applications to be used by our users on any browser. For example, some people like to use IE to open Open source Web site, but some people like Firefox or Chrome.
We expect our web system to work properly on any browser, which will attract more users to use.
The root causes of cross-browser testing are:
Font size mismatch in different browsers
Javascrpit's implementation is different.
CSS, HTML validation is different
Some browsers or low versions do not support HTML5
Page alignment and div size issues
Picture position or size issues
Compatibility issues between the browser and the operating system
The above aspects not only affect the layout, even cause the function is not available, so we need to conduct cross-browser testing.
How to perform cross-browser testing
If we use Selenium webdriver, we can automatically run test cases on different browsers such as IE, Firefox, Chrome, and so on.
To be able to execute test cases simultaneously on different browsers on the same machine, we need multi-threading technology.
The following is a python-based multithreading technique that attempts to launch multiple browsers simultaneously for selenium automated testing.
#-*-coding:utf-8-*-author = u ' Bitter leaf ' from selenium import webdriverimport sysfrom time import sleepfrom threading Import Thread Reload (SYS) sys.setdefaultencoding ("Utf-8") def test_baidu_search (browser, url): Driver = None # You can customize here, add more browsers Support in If browser = = "ie": Driver = webdriver. Ie () elif browser = = "Firefox": Driver = webdriver. Firefox () elif Browser = = "Chrome": Driver = webdriver. Chrome () if Driver = = None:exit () print U "start [case_0001] Baidu search" driver.get (URL) print U "clear search data, enter search keywords" driver.f ind_element_by_id ("kw"). Clear () driver.find_element_by_id ("kw"). Send_keys (U "open source test") Print U "click Baidu button to start search" driver.fi nd_element_by_id ("su"). Click () sleep (3) print U "Close browser, Exit Webdriver" Driver.quit () if name = = "Main": # Browser and home URL dat A = {"ie": "http://www.baidu.com", "Firefox": "Http://www.baidu.com", "Chrome": "Http://www.baidu.com"} # Build Line Cheng threads = [] for b, url in Data.items (): t = Thread (target=test_baidu_search,args= (b,url)) threads. Append (t) # Start all threads for THR in Threads:thr.start ()
Run the above code, you will find three browsers will start to start Baidu Search, is not very interesting? Of course, the above is just a simple demonstration, more practical ability to be excavated.
This article initially demonstrated the use of Python multithreading technology to launch multiple browsers while selenium automated testing, through this example you should learn more in-depth knowledge, and in-depth practical business testing to comb out more appropriate automated testing business scenarios.
As to how to make use of selenium to make the compatibility test well, we still need to dig deeper, and really use the characteristics of selenium well.