0

I have distributed the login code in three .py file.

In first one Browser.locator => I added all the xpath locators and driver as webdriver.Chrome(ChromeDriverManager().install())

In second one => conftest.py I implement the below code

    import pytest
    from Test_Suit.Locator_Declaration_test.test_Browser_Locators import TestBrowserLocator as BL
    
    @pytest.fixture(scope="session")
    def driver_get(request):
        web_driver = BL.dchrome
        cls1 = BL()
        username = BL.username_textbox_xpath
        password = BL.password_textbox_xpath
        login = BL.login_button_xpath
        print("this ia web driver",web_driver)
        session = request.node
        print("This is session",session)
        for item in session.items:
            cls=item.getparent(pytest.Class)
            setattr(cls.obj, "driver", web_driver)
            setattr(cls.obj,"session",session)
            setattr(cls1, "url", url)
            setattr(cls1, "username", username)
            setattr(cls1, "password", password)
            setattr(cls1, "login", login)
            print("______________________")
            yield
            print("___________")
            web_driver.close()
    
    @pytest.mark.usefixtures("driver_get")
    class BaseTest:
         pass

Now in last file TestHomePage.py

    @pytest.mark.run(order=1)
    class TestHomePage(BaseTest):
         def test_setUpBrowser_execution(self):
            self.driver.maximize_window()
            time.sleep(5)
            self.driver.get(self.url)
            current_title = self.driver.title
            print(current_title)

And every time when I try to execute the code it is opening the two Browsers and some of the methods get executed in back browser and some get hanged.

Please let me know the actual solution, how to open the one browser session for all the .py files.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.