Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

Selenium Python run test cases how do i log in once and use the same instance browser

I am new learner on Selenium Python have created some Test Cases in different py file in Selenium Python. Each time a py file runs it opens the browser and navigates to the URL.

-Test (Package)
  -Test_Login.py
  -Test_Search.py
  -Test_Create.py

How to execute the Test_Search.py and Test_Create.py using same instance browser with logged in ?

-Test_Login.py

import unittest
from selenium import webdriver
import time

class Test_Login( unittest.TestCase ):

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome( '../Driver/chromedriver.exe' )
        cls.driver.implicitly_wait( 10 )
        cls.driver.get( "url...etc" )

    def test_A_Login(self):
        ###login action ....etc

    @classmethod
    def tearDownClass(cls):
            cls.driver.quit()
        
if __name__ == '__main_':
    unittest.main()
    

-Test_Search.py

import unittest
from selenium import webdriver
import time

class Test_Search( unittest.TestCase ):

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome( '../Driver/chromedriver.exe' )
        cls.driver.implicitly_wait( 10 )
        cls.driver.get( "url...etc" )

    def test_A_Search(self):
        ###Search testing ....etc

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()
        
if __name__ == '__main_':
    unittest.main()
question from:https://stackoverflow.com/questions/65901457/selenium-python-run-test-cases-how-do-i-log-in-once-and-use-the-same-instance-br

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...