python呼叫模組時傳參出錯
首先定義了一個Login模組,傳參是兩個:username,password
#coding=utf-8
def login(self,username,password):
driver=self.driver
self.driver.implicitly_wait(30)#不加等待會出錯
driver.switch_to.frame(0)
driver.find_element_by_class_name("dlemail").clear()
driver.find_element_by_class_name('dlemail').send_keys("username")
driver.find_element_by_class_name('dlpwd').clear()
driver.find_element_by_class_name('dlpwd').send_keys("password")
driver.find_element_by_id("dologin").click()
def logout(self):
driver=self.driver
driver.find_element_by_link_text(u"退出").click()
driver.quit()
在Test.login中呼叫該模組:
#coding=utf-8
from selenium import webdriver
import unittest,time
from public import Login
class TestLogin(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "http://www.126.com/"
self.verificationErrors = []
def test_login(self):
driver=self.driver
driver.get(self.base_url)
Login.login(self,"jinbian3333","jinbian76")#傳參是這兩個
text=driver.find_element_by_id("spnUid").text
self.assertEqual(text,"[email protected]")
Login.logout(self)
def tearDown(self):
self.driver.quit()
self.assertEqual([],self.verificationErrors)
if __name__ == '__main__':
unittest.main()
可是執行後發現出錯:
明明傳參是"jinbian3333","jinbian76",為什麼登入資訊是圖中呢?
回頭檢視被呼叫模組,
按我理解就是 加了" " 就不是變量了,是常量了, 你呼叫了該模組,即使傳參 它還是按照模組本身的設定:“username”"password"執行