In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge about "how to use selenium to open multiple browsers". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
preface
In web testing, one of the inevitable tests is browser compatibility testing. Before automated testing, we always painstakingly install N browsers on one or more machines, and then manually verify the main business process and key functional modules on different browsers to check whether our web application can work properly on different browsers or different versions of browsers.
Let's take a look at how Python selenium can be used to automate cross-browser testing.
What is Cross-Browser Testing?
Cross-browser testing is a branch of functional testing that verifies that web applications work correctly on different browsers.
Why cross-browser testing is needed
In general, we expect web-like apps to be usable by our users on any browser. For example, some people prefer Internet Explorer, while others prefer Firefox or Chrome.
We expect our web system to work well in any browser, which will attract more users.
The root causes of the need for cross-browser testing are:
1. font size mismatch in different browsers
The implementation of javascrpit is different
3. CSS and html validation are different
4. Some browsers or lower versions do not support HTML5
5. Page alignment and div size issues
6. Picture location or size issues
7. Compatibility issues between browsers and operating systems
These aspects not only affect the layout, but even cause functionality to be unavailable, so we need to do cross-browser testing.
How to perform cross-browser testing
If we use selenium webdriver, we can automatically run test cases on IE, Firefox, Chrome, etc.
In order to execute test cases simultaneously on different browsers on the same machine, we need multithreading.
Below we try to launch multiple browsers simultaneously for selenium automation testing based on Python's multithreading technology.
#-*- coding:utf-8 -*-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 here, add more browser support in 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 data in search, enter search keywords" driver.find_element_by_id("kw").clear() driver.find_element_by_id("kw").send_keys(u"Rui Jiangyun") print u"click baidu button to start searching" driver.find_element_by_id("su").click() sleep(3) print u"Close browser and exit webdriver" driver.quit() if __name__ == "__main__": #browser and home url data = { "ie":"http://www.baidu.com", "firefox":"http://www.baidu.com", "chrome":"http://www.baidu.com" } #Build Threads 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()
Run the above code, you will find IE, firefox, chrome will start Baidu search, is not very interesting? Of course, the above is just a simple demonstration, and more practical abilities remain to be explored.
summary
This article initially demonstrated the use of python multithreading technology to start multiple browsers at the same time for selenium automation testing, through this example to learn more in-depth knowledge, and in-depth combination with actual business testing to comb out more appropriate automation testing business scenarios.
"How to use selenium to open multiple browsers" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.