Python detailed python multi-threaded selenium cross-browser testing

Source: Internet
Author: User

Objective

In Web testing, one of the unavoidable tests is browser compatibility testing, where we always have to install n browsers on one or more machines without automated testing, and then manually verify the main business process and key function module functions on different browsers to detect different browsers or versions of the Browser. Whether our web App works Properly.

Let's take a look at how to automate Cross-browser testing using Python selenium.

What is Cross-browser testing

Cross-browser testing is a branch of functional testing to verify that Web apps work correctly on different Browsers.

Why Cross-browser testing is required

typically, We expect web-class applications to be used by our users on any browser. For example, Some people like to use IE to open Open source http://www.testingunion.com Web site, But some people like Firefox or Chrome.

We expect our web system to work properly on any browser, which will attract more users to Use.

The root causes of Cross-browser testing are:

Font size mismatch in different browsers

    1. Javascrpit's implementation is Different.
    2. css, HTML validation is different
    3. Some browsers or low versions do not support HTML5
    4. Page alignment and div size issues
    5. Picture position or size issues
    6. Compatibility issues between the browser and the operating system

The above aspects not only affect the layout, even cause the function is not available, so we need to conduct cross-browser testing.

How to perform Cross-browser testing

If we use Selenium webdriver, we can automatically run test cases on different browsers such as ie, firefox, chrome, and so On.

To be able to execute test cases simultaneously on different browsers on the same machine, we need multi-threading technology.

The following is a python-based multithreading technique that attempts to launch multiple browsers simultaneously for selenium automated testing.

?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 #-*- coding:utf-8 -*-__author__ = u‘苦叶子‘from selenium import webdriverimport sysfrom time import sleepfrom threading import Threadreload(sys)sys.setdefaultencoding("utf-8") def test_baidu_search(browser, url):  driver = None  # 你可以自定义这里,添加更多浏览器支持进来  if browser == "ie":    driver = webdriver.Ie()   elif browser == "firefox":    driver = webdriver.Firefox()   elif browser == "chrome":    driver = webdriver.Chrome()   if driver == None:    exit()  print u"开始[case_0001]百度搜索"  driver.get(url)  print u"清除搜索中数据,输入搜索关键词"  driver.find_element_by_id("kw").clear()  driver.find_element_by_id("kw").send_keys(u"开源优测")  print u"单击 百度一下 按钮 开始搜索"  driver.find_element_by_id("su").click()  sleep(3)  print u"关闭浏览器,退出webdriver"  driver.quit()if __name__ == "__main__":  # 浏览器和首页url  data = {    "ie":"http://www.baidu.com",     "firefox":"http://www.baidu.com",     "chrome":"http://www.baidu.com"    }  # 构建线程   threads = []   for b, url in data.items():     t = Thread(target=test_baidu_search,args=(b,url))    threads.append(t)   # 启动所有线程  for thr in threads:    thr.start()

Run the above code, you will find three browsers will start to start Baidu search, is not very interesting? Of course, the above is just a simple demonstration, more practical ability to be excavated.

Summarize

This article initially demonstrated the use of Python multithreading technology to launch multiple browsers while selenium automated testing, through this example you should learn more in-depth knowledge, and in-depth practical business testing to comb out more appropriate automated testing business Scenarios.

As to how to make use of selenium to make the compatibility test well, we still need to dig deeper, and really use the characteristics of selenium Well.

The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support the script Home.

Original Link: http://www.jianshu.com/p/9a05cc7d0f96#

Python detailed python multi-threaded selenium cross-browser testing

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.