Python+selenuim+django Web Automation testing, opening the service opens the browser.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.