Selenium_ Multithreaded Execution Test Cases

Source: Internet
Author: User
Tags selenium grid

Multithreaded execution of test cases

Here, for example, Baidu search, through different browsers to start different threads.

1 #!/usr/bin/env python2 #_*_ coding:utf-8 _*_3 __author__='Yinjia'4 5  fromThreadingImportThread6  fromSeleniumImportWebdriver7  fromTimeImportCtime,sleep8 9 #Test CasesTen defTest_baidu (browser,search): One     Print('start: {0}'. Format (CTime ())) A     Print('browser: {0}'. Format (browser)) -     ifBrowser = ="IE": -Driver =Webdriver. Ie () the     elifBrowser = ="Chrome": -Driver =Webdriver. Chrome () -     elifBrowser = ="FF": -Driver =Webdriver. Firefox () +     Else: -         Print("browser parameter is incorrect, only for IE, FF, Chrome") +  ADriver.get ("http://www.baidu.com") atDRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys (search) -DRIVER.FIND_ELEMENT_BY_ID ("su"). Click () -Sleep (2) - driver.quit () -  - if __name__=="__main__": inLists = {'Chrome':'C + +','IE':'JAVA','FF':'python'} -Threads = [] toFiles =Range (len (lists)) +  -     #Creating Threads the      forBrowser,searchinchLists.items (): *t = Thread (target=test_baidu,args=(browser,search)) $ threads.append (t)Panax Notoginseng     #Start Thread -      forTinchFiles: the Threads[t].start () +      forTinchFiles: A Threads[t].join () the     Print('end: {0}'. Format (CTime ())) +  - Operation Result: $Start:mon 20 00:09:50 2018 $ Browser:chrome -Start:mon 20 00:09:50 2018 - Browser:ie theStart:mon 20 00:09:50 2018 - Browser:ffWuyiEnd:mon 20 00:10:09 2018

It can be seen running three different browser environments to execute test cases.

Multithreaded distributed execution test cases

The Selenium grid itself does not provide concurrent execution cases, but provides a multi-system, multi-browser execution environment, in view of the fact that concurrent execution requires the use of multithreaded technology in conjunction with a grid for distributed concurrency execution of test cases.

Start a hub master and a node branch on one host, and another host to start a node branch, as follows:

    • Start the native hub host: Java-jar selenium-server-standalone-2.53.0.jar-role hub [default 4444 port]
    • Start the Native Node branch node: Java-jar selenium-server-standalone-2.53.0.jar-role node-port 5555
    • Start Node branch nodes on the remote host: Java-jar selenium-server-standalone-2.53.0.jar-role node-port 6666-hub http://192.168.31.210:4444/ Grid/register
1 #!/usr/bin/env python2 #_*_ coding:utf-8 _*_3 __author__='Yinjia'4 5 6  fromThreadingImportThread7  fromSeleniumImportWebdriver8  fromTimeImportCtime,sleep9 Ten #Test Cases One defTest_baidu (host,browser): A     Print('start:{0}'. Format (CTime ())) -     Print(Host,browser) -DC = {'Browsername': Browser} theDriver = Webdriver. Remote (command_executor=Host, -desired_capabilities=DC) -Driver.get ("http://www.baidu.com") -DRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys (browser) +DRIVER.FIND_ELEMENT_BY_ID ("su"). Click () -Sleep (2) + driver.quit () A  at if __name__=="__main__": -     #startup parameters (specify running host and browser) -Lists = {'Http://127.0.0.1:4444/wd/hub':'Chrome', -              'Http://192.168.31.230:6666/wd/hub':'Internet Explorer', -              'Http://1127.0.0.1:5555/wd/hub':'Firefox'} -Threads = [] inFiles =Range (len (lists)) -  to     #Creating Threads +      forBrowser,searchinchLists.items (): -t = Thread (target=test_baidu,args=(browser,search)) the threads.append (t) *     #Start Thread $      forTinchFiles:Panax Notoginseng Threads[t].start () -      forTinchFiles: the Threads[t].join () +     Print('end: {0}'. Format (CTime ()))

Selenium_ Multithreaded Execution Test Cases

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.