一、前言
通过传递不同的参数来测试不同的浏览器,用来做浏览器兼容性测试。
二、示例
# -*- coding:utf-8 -*-
# @File:base.py
from selenium import webdriver
import os
class Base:
def setup(self):
browser = os.getenv("browser")
if browser =='firefox':
self.driver = webdriver.Firefox()
elif browser =='headless':
self.driver = webdriver.PhantomJS()
else:
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(5)
self.driver.maximize_window()
def teardown(self):
self.driver.quit()
# -*- coding:utf-8 -*-
# @File:test_ChromeFirefox.py
from selenium_test.selenium_frame_window.base import Base
class TestChromeFirefox(Base):
def test_demo1(self):
self.driver.get("https://www.baidu.com/")
在终端指定browser相应参数,可以用对应的浏览器进行测试。
网友评论