Web自动化测试项目(六)多环境执行
需求
使用命令行运行脚本,可以指定测试/预发布/生产环境的url,如果找不到该环境变量则默认为测试环境
python3 xxxxxx.py test
修改constants.py
# DOMAIN = 'https://www.tapd.cn/'
LOGIN_URL = '/cloud_logins/login'
TIMEOUT = 5
POLL_FREQUENCY = 0.5
DOMAIN = {
'test':'https://www.tapd.cn/',
'product':'https://www.baidu.com'
}
修改base_page.py
import sys
class BasePage():
def get_url(self, path=None):
if path != None:
try:
domain = DOMAIN[sys.argv[-1]]
except Exception as e:
domain = DOMAIN['test']
url = domain + path
else:
url = None
if url != None:
self.driver.get(url)
推荐阅读
Python Unittest - 根据不同测试环境跳过用例详解