Selenium+python Automation 92-Multithreading launches multiple different browsers

Source: Internet
Author: User

Objective

If you want to run the same set of test code with multiple browsers, Driver=webdriver. Firefox () driver here can't be written dead, you can parameterize the name of the browser.
Follow-up if you want to implement multi-threaded and start the browser to execute the use case, with the Tomorrow module, set the number of threads to apply it.

Launch browser

1. In order to achieve the flexible switching of multiple browsers, you can start the browser to write a function, parameters with the browser name on the line

defStartbrowser (name):"""Open Browser functions, "Firefox", "Chrome", "ie", "PHANTOMJS""""    Try:        ifName = ="Firefox" orName = ="Firefox" orName = ="FF":            Print("Start Browser Name:firefox") Driver=Webdriver. Firefox ()returnDriverelifName = ="Chrome" orName = ="Chrome":            Print("Start Browser Name:chrome") Driver=Webdriver. Chrome ()returnDriverelifName = ="IE" orName = ="Ie":            Print("Start Browser Name:ie") Driver=Webdriver. Ie ()returnDriverelifName = ="Phantomjs" orName = ="Phantomjs":            Print("Start Browser name:p Hantomjs") Driver=Webdriver. PHANTOMJS ()returnDriverElse:            Print("Not found this browser,you can use ' Firefox ', ' Chrome ', ' ie ' or ' phantomjs '")    exceptException as msg:Print("The exception occurred when starting the browser:%s"%str (msg))

Multithreading launches different browsers

1. Code reference:

#Coding:utf-8 fromSeleniumImportWebdriverImport Time fromTomorrowImportThreadsdefStartbrowser (name):"""Open Browser functions, "Firefox", "Chrome", "ie", "PHANTOMJS""""    Try:        ifName = ="Firefox" orName = ="Firefox" orName = ="FF":            Print("Start Browser Name:firefox") Driver=Webdriver. Firefox ()returnDriverelifName = ="Chrome" orName = ="Chrome":            Print("Start Browser Name:chrome") Driver=Webdriver. Chrome ()returnDriverelifName = ="IE" orName = ="Ie":            Print("Start Browser Name:ie") Driver=Webdriver. Ie ()returnDriverelifName = ="Phantomjs" orName = ="Phantomjs":            Print("Start Browser name:p Hantomjs") Driver=Webdriver. PHANTOMJS ()returnDriverElse:            Print("Not found this browser,you can use ' Firefox ', ' Chrome ', ' ie ' or ' phantomjs '")    exceptException as msg:Print("The exception occurred when starting the browser:%s"%str (msg)) @threads (5)defrun_case (name): Driver=startbrowser (name) driver.get ("https://www.cnblogs.com/yoyoketang/") Time.sleep (3)    Print(Driver.title) driver.quit ()if __name__=="__main__": Names= ["Chrome","FF","IE"]     forIinchnames:run_case (i)

2. Operation Result:

Tags: selenium

Selenium+python Automation 92-Multithreading launches multiple different browsers

Related Article

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.