python selenium all test in one browser

  • 0
  • 1
  • Question
  • Updated 9 months ago
class Login(unittest.TestCase):
@classmethod
def setUpClass(cls):
    cls.browser = webdriver.Chrome()

def setUp(self):
    self.browser.get("www")
    username = self.browser.find_element_by_id("username")
    password = self.browser.find_element_by_id("password")
    username.send_keys("aaaa")
    password.send_keys("ssswww")
    self.browser.find_element_by_id("button").click()

def tearDown(self):
    self.browser.get("about:blank")

@classmethod
def tearDownClass(cls):
    cls.browser.quit()

When I have log, because I must log in every class (10) My class with test is similar for example:

 class Test1(Login):
my code with test step

And now I understand, the

import pytest
from selenium import webdriver
@pytest.fixture(scope='module')
def driver():
    d = webdriver.Chrome()
    yield d
    d.quit()

For example test class: (I understand that I have to place login in one of the test classes) Selenium

class Test1:
def test_google(self, driver):
      driver.get('https://google.com')
      driver.get("www")
      username = driver.find_element_by_id("username")
      password = driver.find_element_by_id("password")
      username.send_keys("aaaa")
      password.send_keys("ssswww")
      driver.find_element_by_id("button").click()

class Test2: #in new file 
def function(self, driver):

And Test3, Test4 ... Test10.

And because I do everything in one browser, I do not have to log in anymore?
Photo of Elena

Elena

  • 110 Points 100 badge 2x thumb

Posted 9 months ago

  • 0
  • 1

Be the first to post a reply!