Python multi-threaded selenium cross-browser testing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.