The first time to use Python Django to do page automation, encountered some problems. Now do the recording.
The desired effect:
In the test interface, click the button to submit the test data and execute testcase. Then open the corresponding browser to execute.
The actual problem encountered:
Turning on the Django service opens the browser.
The query problem is caused by driver= webdriver. Chormen () is executed at initialization. So the browser always opens first.
Workaround:
Class webd:
Driver = None
@classmethod #类修饰 (I don't know what that means yet)
def setupclass (CLS):
Print (' Start ')
if Cls.driver = = None:
Cls.driver = Webdriver. Chrome ()
@classmethod
def teardownclass (CLS):
Print (' End ')
If Cls.driver:
Cls.driver.quit ()
Cls.driver = None
The invocation is instantiated first:
Webd.setupclass () #用例开始前执行实例化
Driver = Webd.driver
Webd.teardownclass () #结束用例时执行关闭
Summarize:
Before solving the thought is to be driver = Webdriver. Chrome () is defined in the class, but is not decorated. So I wrote the following code:
Class webd:
def setupclass (def):
Print (' Start ')
Def.driver = Webdriver. Chrome ()
def teardownclass (def):
Print (' End ')
Def.driver.quit ()
When it is actually running, it is still initialized to open the browser. So the idea is right, just go down the line of thought.
Python+selenuim+django Web Automation testing, opening the service opens the browser.