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 leaves 'From seleniumImport WebdriverImport SysFrom timeImport SleepFrom threadingImport threadreload (SYS) sys.setdefaultencoding ("Utf-8")DefTest_baidu_search(Browser, URL): Driver =None# You can customize here, add more browsers support come inif browser = ="ie": Driver = webdriver. Ie ()elif Browser = ="Firefox": Driver = webdriver. Firefox ()elif Browser = ="Chrome": Driver = webdriver. Chrome ()If Driver = =None:exit ()PrintU "start [case_0001] Baidu search" driver.get (URL)PrintU "Clear search data, enter search keywords" driver.find_element_by_id ("KW"). Clear () driver.find_element_by_id ("KW"). Send_keys (U "open source test")PrintU "click Baidu button to start searching" driver.find_element_by_id (3) print u "Close browser, Exit Webdriver" Driver.quit () if __name__ = " __main__ ": # Browser and home page URL data = {" ie ": " http://www.baidu.com ", " Firefox ": " Chrome ": " http://www.baidu.com "} # build thread threads = [] for B, url in data.items (): t = t Hread (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.
Summarize
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.
Python multi-threaded selenium cross-browser testing