driver = self.driver AttributeError:“ loginpage”对象没有属性“ driver”

时间:2018-09-07 10:17:48

标签: selenium automated-tests python-unittest

demo1.py

from selenium import webdriver
import unittest
from selenium.webdriver.common.action_chains import ActionChains
import pandas as pd
import warnings
class Login(unittest.TestCase):
    @classmethod
    def setUPClass(cls):
       cls.driver=webdriver.Firefox()

       cls.driver.maximize_window()
       cls.driver.get("http:***********")


#     @classmethod 
#     def tearDownClass(cls):
#      cls.driver.close()


if __name__ == '__main__':
     unittest.main()

demo2.py

from selenium import webdriver
import unittest
from selenium.webdriver.common.action_chains import ActionChains
import pandas as pd
import warnings
from demo import demo1 

class loginpage(demo1.Login):
    def test_login(self):
        driver=self.driver
        loginExcel = pd.read_excel(r"/root/eclipse-workspace/NMS/excel/login.xlsx")
        user = loginExcel["user"]
        pwd = loginExcel["pword"]


        i=0
        for i in range(2):
            username = driver.find_element_by_name('username')  
            driver.implicitly_wait(10)
            driver.find_element_by_name('username').send_keys(user.iloc[i])
            print("The username [" + user.iloc[i] + "] is entered")

            password= driver.find_element_by_name('password')
            driver.find_element_by_name('password').send_keys(pwd.iloc[i])

            print("The Password [" + pwd.iloc[i] + "] is entered")
            driver.implicitly_wait(10)

            Login = driver.find_element_by_name('login').click()
            driver.implicitly_wait(10)

if __name__ == '__main__':
    unittest.main()

demo3.py 将熊猫作为pd导入 从selenium.webdriver.support.ui导入选择 导入演示1 从demo2导入登录页面 从selenium.webdriver.common.action_chains导入ActionChains

导入demo2

import unittest

class configuration(demo1.Login):
    def test_demo(self):
        driver=self.driver

        test=loginpage().test_login()

        conf= driver.find_element_by_link_text('Configuration')
        hover=ActionChains(self.driver).move_to_element(conf)
        hover.perform()

if __name__ == '__main__':
    unittest.main()

**追踪(最近通话):   在test_demo中,文件“ /root/eclipse-workspace/NMS/src/demo/demo3.py”,第23行     test = loginpage()。test_login()   在test_login中,文件“ /root/eclipse-workspace/NMS/src/demo/demo2.py”,第21行     driver = self.driver

AttributeError:“登录页面”对象没有属性“驱动程序”

错误:test_login(demo2.loginpage)

回溯(最近通话最近):   在test_login中,文件“ /root/eclipse-workspace/NMS/src/demo/demo2.py”,第21行     driver = self.driver

AttributeError:“登录页面”对象没有属性“驱动程序”

在0.000s内进行2次测试 失败(错误= 2)**

0 个答案:

没有答案