I
I
Ivan Petrov2017-01-25 18:13:52
Python
Ivan Petrov, 2017-01-25 18:13:52

Why does pytest open browser when running test 2==2?

Greetings.
I'm trying to test a website with pytest and selenium webdriver. In the main fixture, do I create and return a Browser object? in which there will be methods for working with tabs, browser, etc. The problem is that even in a simple test where 2 == 2 is checked, the browser opens.
conftest.py file

import pytest
from app.browser import Browser

@pytest.fixture(scope="session")
def browser(request):
    # TODO add authorization check
    app = Browser()
    #request.addfinalizer(app.destroy)
    return app

browser.py - here is the main class for working with the browser
from selenium import webdriver
from config import *


class Browser:

    def __init__(self):
        if browser == "firefox":
            self.browser = webdriver.Firefox()
        elif browser == "chrome":
            self.browser = webdriver.Chrome()
        elif browser == "ie":
            self.browser = webdriver.Ie()
        self.browser.implicitly_wait(5)

    def open_me(self):
        self.browser.get('http://google.ru')

    def destroy(self):
        self.browser.quit()

the test itself
def test_open_page(browser):
    assert 2==2

Why does the browser open and then immediately close when I run the test? I'm passing the fixture to the test, but in the constructor I'm just assigning variables without opening any site.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-01-26
@bitande

Browser starts opening with webdriver.some_browser() instead of after driver.get(url)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question