2017-09-06 64 views
0

我試圖使WebDriver實例通用。我創建了一個小的Python文件來實例化的webdriver瀏覽器沒有在Python中使用Selenium啓動

這裏是我的代碼

#Driver.py 
from selenium import webdriver 

Instance = None 

def Initialize(): 

    global Instance 
    Instance = webdriver.Chrome("C:\\mystuff\\Browser\\chromedriver.exe") 
    Instance.implicitly_wait(5) 
    return Instance 

def CloseDriver(): 

    global Instance 
    Instance.quit() 

這是正在使用Commonfunctions.py

import Driver 

class LoginPage: 

    @staticmethod 
    def GoToURL(url): 
     print "In GoTo URL" 
     Driver.Instance.get(url) 

最後我測試文件

import unittest 
import Driver 
from CommonFunctions import LoginPage 


class LoginTest(unittest.TestCase): 

    def setUp(self): 
     Driver.Initialize() 

    def testUserCanLogin(self): 
     LoginPage.GoToURL("http://www.gmail.com") 

當我嘗試執行此操作時沒有錯誤,我收到消息「在PyCharm控制檯中使用exit(0)完成進程」。但是,瀏覽器從未啓動。 如果我嘗試在一個塊中完成,那麼瀏覽器會順利啓動。

我想創建一個簡單的框架,這是我的第一步。如果您有任何其他建議,請指導我。

謝謝!

+0

具有u安裝壁虎驅動程序?嘗試安裝它。那麼它可能工作! – rhea

+0

你如何進行測試?你使用了什麼命令 –

回答

0

認沽以下主要在你測試類,

class LoginTest(unittest.TestCase): 

    def setUp(self): 
     Driver.Initialize() 

    def testUserCanLogin(self): 
     LoginPage.GoToURL("http://www.gmail.com") 

if __name__ == "__main__": 
    unittest.main() 
相關問題