Selenium_python automated cross-browser test execution (simple multithreaded case)

Source: Internet
Author: User

Occurrence background:

Cross-browser testing is a branch of functional testing to verify that Web apps work correctly on different browsers, and generally we expect web-class apps to be used by our users on any browser, for example, some people like to use Internet Explorer, Some people like Firefox or some people like chrome. We expect the system to be used properly on any browser to attract more users.

Source of the problem:

The root causes of our cross-browser testing are:

1, the web and CSS styles in different browsers display the results are not the same; (ie has been the headache of the previous development of the Internet has been accompanied by the windows for many years)

2, javascrpt in different browser implementation, such as some post-click action and return results after clicking, and so on;

3, some low-version browser does not support H5;

4, picture position size problem, font size problem;

5, Div, span ... such as label float property issues, etc.;

6, browser and operating system compatibility issues;

The above points are slightly different page style, serious will cause some features are not available;

Solution Ideas:

How to perform cross-browser testing, manual is to install more than one browser to perform manual point-and-click testing, but found that the problem may sometimes be the previous cache, etc., and then turn off the browser to clear the history of the browsing record to do the operation again, how automation solves this problem? We can use selenium webdriver in different browsers (Firefox, IE, Chrome ... Run the test case execution test;

The following is a python-based multithreaded technology to try to launch multiple browsers for selenium to perform automated testing;

The specific code is as follows:

#-*-coding:utf-8-*-__author__='dong.c' fromSeleniumImportWebdriverImportSYSImportThreadImportThreading fromTimeImportsleepreload (SYS) sys.setdefaultencoding ("Utf-8")defTest_baidu_search (browser,url): Driver=None#You can customize this here, add more browser support to come in    ifBrowser = ="IE": Driver=webdriver.ie ()elifBrowser = ="Firefox": Driver=Webdriver. Firefox ()elifBrowser = ="Chrome": Driver=Webdriver. Chrome ()ifDriver = =none:exit ()PrintU"start "case_001" Baidu search"driver.get (URL)PrintU"clear the data in the search, enter search keywords"driver.find_element_by_id ("kw"). Clear () driver.find_element_by_id ("kw"). Send_keys (U"Blog Park")    PrintU"Click Baidu button to start testing"driver.find_element_by_id ("su"). Click () Sleep (3)    PrintU"Close Browser, exit Webdriver"driver.quit ()if __name__=="__main__":    #browser and Home URLdata = {        "IE":"http://www.baidu.com",        "Firefox":"http://www.baidu.com",        "Chrome":"http://www.baidu.com"    }    #build and start a thread     forB,urlinchData.items (): t= Threading. Thread (target = test_baidu_search,args=(B,url)) T.start ()

Operation Result:

Run the above code, you will find that 3 browsers will start to start Baidu Search, here just do the simplest core area of multi-threaded demonstration, you can organize the write unittest to add some assertions, comb out more suitable for automated testing business scenarios, As for how to use selenium more deeply to make the software compatibility better, there is more need to dig;

Selenium_python automated cross-browser test execution (simple multithreaded case)

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.