问题描述: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] 请广大网友详细说明下这个是什么原因呢!


↙↙↙阅读原文可查看相关链接,并与作者交流