Python multi-thread Selenium cross-browser test, pythonselenium

Source: Internet
Author: User

Python multi-thread Selenium cross-browser test, pythonselenium

Preface

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 like to use IE to open the Open Source test web site http://www.testingunion.com, but some people like 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

  1. Implementation of javascrpit is different
  2. Css and html verification are different
  3. Some browsers or earlier versions do not support HTML5
  4. Page alignment and div size Problems
  5. Image Location or size Problems
  6. 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'kubernetes 'from selenium import webdriverimport sysfrom time import sleepfrom threading import Threadreload (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.

Summary

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 all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.