TA的每日心情 | 开心 2017-2-23 09:15 |
---|
签到天数: 13 天 连续签到: 1 天 [LV.3]测试连长
|
问题描述:public1.py中写了一个类,下面有个调用浏览器的方法,public1.py中写了一个登录的方法 但在webtest1同时引用这两个文件中的方法报错
public1.py代码:
# coding=utf-8
from selenium import webdriver
class BrowserEngine(object):
"""
定义一个浏览器引擎类,根据browser_type的值去,控制启动不同的浏览器,这里主要是IE,Firefox, Chrome
"""
def __init__(self, driver):
self.driver = driver
browser_type = "Chrome" # maybe Firefox, Chrome, IE
def get_browser(self):
"""
通过if语句,来控制初始化不同浏览器的启动,默认是启动Chrome
:return: driver
"""
if self.browser_type == 'Firefox':
driver = webdriver.Firefox()
elif self.browser_type == 'Chrome':
driver = webdriver.Chrome()
elif self.browser_type == 'IE':
driver = webdriver.Ie()
else:
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(50)
driver.get("https://sso.dev.weixiuhui.cn/cas/login?service=https://sso.dev.weixiuhui.cn/sso_base/a/cas")
public.py代码:#web登录方法
def Login1(self):
self.driver.find_element_by_id("username").send_keys("15111111112")
# 输入密码
self.driver.find_element_by_id("password").send_keys("123456")
# 输入验证码
self.driver.find_element_by_id("captcha").send_keys("8888")
# 登录
self.driver.find_element_by_name("submit").click()
webtest1脚本:
# coding:utf-8
from selenium import webdriver
import unittest
from appProject.public import Login1
from appProject.public1 import BrowserEngine
class Login_Logout1(unittest.TestCase):
def setUp(self):
browserengine = BrowserEngine(self)
self.driver = browserengine.get_browser()
def test(self):
Login1(self)
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main()
报错信息:
[size=17.0667px]F:\Python27\python.exe "F:\PyCharm Community Edition 2016.3\helpers\pycharm\utrunner.py" F:\appiumDemo\appProject\cases\wentest1.py trueTesting started at 9:43 ...ErrorTraceback (most recent call last): File "F:\appiumDemo\appProject\cases\wentest1.py", line 16, in test Login1(self) File "F:\appiumDemo\appProject\public.py", line 59, in Login1 self.driver.find_element_by_id("username").send_keys("15111111112")AttributeError: 'NoneType' object has no attribute 'find_element_by_id'ErrorTraceback (most recent call last): File "F:\appiumDemo\appProject\cases\wentest1.py", line 13, in tearDown self.driver.quit()AttributeError: 'NoneType' object has no attribute 'quit'Process finished with exit code 0
[size=17.0667px]请广大网友详细说明下这个是什么原因呢!
|
|