I am doing pytest-bdd with selenium python. I am doing BDD and page object model. when i execute test, the url value is not passed to the browser.My actual code is
Browser instantiating file is as below
@pytest.fixture()
def setup(browser):
if browser == 'firefox':
driver =
webdriver.Chrome(service=ChromeService(ChromeDriverManager().install( ))) return driver else: driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install(. ))) return driver
def pytest_addoption(parser):
parser.addoption("--browser")
@pytest.fixture()
def browser(request):
return request.config.getoption("--browser")
config.ini
[common details]
Baseurl=www.https://google.com
Reading config.ini values in read_config.py file as below.
import configparser
# reading config file
config = configparser.RawConfigParser()
file = "/Users/lgopal/PycharmProjects/Devices/Configuration/config.ini"
config.read(file)
class ReadConfig:
@staticmethod
def get_application_url():
url = config.get("common details", "Baseurl")
print(url)
return url
page object for login is
class Login:
base_url = ReadConfig.get_application_url()
textbox_email_name = "email"
textbox_password_name = "password"
button_login_xpath = "//button[@type='submit']"
def __init__(self,driver):
self.driver = driver
def set_user_name(self, username):
self.driver.find_element(self.textbox_email_name).clear()
self.driver.find_element(self.textbox_email_name).send_keys(username)
def set_password(self, password):
self.driver.find_element(self.textbox_password_name).clear()
self.driver.find_element(self.textbox_password_name).send_keys(password)
def click_login_button(self):
self.driver.find_element(self.button_login_xpath).click()
def get_url(self):
return self.driver.get(self.base_url)
The actual test page of step definition file using pytest-bdd is as below
import pytest
from pytest_bdd import scenario, given, when, then, parsers
from pytest_bdd.parsers import parse
import conftest
from pageObject.loginPage import Login
@when(parsers.parse('enter {username} and {password}'))
def test_user_credentials(username, password, setup):
login = Login(setup)
login.set_user_name(username)
login.set_password(password)
@given("click login button.")
def test_click_login_button(setup):
login = Login(setup)
login.click_login_button()
@then("User should be directed to Home Page.")
def test_redirecting_to_home(setup):
print("directed to home page")
in this case, it instantiate the browser, but the browser, but the url value is not passed.it exit s the test.
Selenium driver.get(String url) expected url formats:"http://www.example.com" or "https://www.example.com"
change your url like "https://www.google.com/" and try again