Python multi-thread Selenium cross-browser test description

Source: Internet
Author: User
In web testing, an inevitable test is browser compatibility testing. before automated testing, we always try to install N browsers on one or more machines, then, manually verify the main business flow and key function module functions in different browsers to check whether our web applications work properly in different browsers or different versions of browsers. In web testing, an inevitable test is browser compatibility testing. before automated testing, we always try to install N browsers on one or more machines, then, manually verify the main business flow and key function module functions in different browsers to check whether our web applications work properly in different browsers or different versions of browsers.

Next we will look at how to use python selenium for automated cross-browser testing.

What is cross-browser testing?

Cross-browser testing is a branch of functional testing to verify that web applications can work properly on different browsers.

Why cross-browser testing?

Generally, we expect web applications to be used by our users in any browser. For example, some people prefer to use IE to open the open-source site, but some prefer firefox or chrome.

We expect that our web system can work normally on any browser, which will attract more users.

The root cause of cross-browser testing is:

Different browser font sizes do not match

Implementation of javascrpit is different

Css and html verification are different

Some browsers or earlier versions do not support HTML5

Page alignment and p size problems

Image location or size problems

Compatibility between browsers and operating systems

The above aspects not only affect the layout, but may even cause function unavailability. Therefore, we need to perform cross-browser testing.

How to perform cross-browser testing

If selenium webdriver is used, we can automatically run test cases on IE, firefox, chrome, and other browsers.

To execute test cases simultaneously on different browsers on the same machine, we need multithreading technology.

Next we try to start multiple browsers at the same time based on the python multi-thread technology for selenium automated testing.

#-*-Coding: UTF-8-*-author = u 'bitter leaf 'from selenium import webdriverimport sysfrom time import sleepfrom threading import Thread reload (sys) sys. setdefaultencoding ("UTF-8") def test_baidu_search (browser, url): driver = None # you can customize it here. add more browsers to support it. if browser = "ie ": driver = webdriver. ie () elif browser = "firefox": driver = webdriver. firefox () elif browser = "chrome": driver = webdriver. chrome () if driver = None: exit () print u "start [case_0001] Baidu search" driver. get (url) print u "clear search data, enter search keyword" driver. find_element_by_id ("kw "). clear () driver. find_element_by_id ("kw "). send_keys (u "open source test") print u "click Baidu to start searching" driver. find_element_by_id ("su "). click () sleep (3) print u "close the browser and exit webdriver" driver. quit () if name = "main": # browser and Homepage url data = {"ie ":" http://www.baidu.com "," Firefox ":" http://www.baidu.com "," Chrome ":" http://www.baidu.com "} # Build thread threads = [] for B, url in data. items (): t = Thread (target = test_baidu_search, args = (B, url) threads. append (t) # Start all threads for thr in threads: thr. start ()

Running the code above, you will find that all three browsers start to start Baidu search, isn't it interesting? Of course, the above is just a simple demonstration, and more practical capabilities need to be explored.

This article demonstrates how to use python multithreading technology to start multiple browsers and perform selenium automated testing at the same time. through this example, you should learn more in-depth knowledge, and in-depth integration with actual business testing to find out more suitable automated testing business scenarios.

As for how to make better use of selenium to test compatibility, we still need to make in-depth research and mining to make good use of selenium's characteristics.

The above is the detailed description of the Python multi-threaded Selenium cross-browser test. For more information, see other related articles in the first PHP community!

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.