I am new to pytest-bdd. I have to implement the automation framework from the scratch. SO I have followed some material and implemented with small framework very basic. When I run the test I can see webdriver is not getting started at all and I don't see any error. I am not sure how to fix this issue. Could anyone help me what is the root cause of the issue I need some examples with pytest-bdd page object model implementation?
** My project structure** [![projectstructure][1]][1]
Inside the tests directory I have features and step_def directory is there. Inside the steps_def I have a test_file_name.py and init file is there.
Inside the page objects directory I have basepage and loginpage python file is there
Basepage.py
"""
Base page which has base URL and locators and parent class for other classes
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class Base_Page:
"Base page which has locators and URL"
def __init__(self,driver):
self.driver = driver
def do_click(self,by_locator):
WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(by_locator)).click()
def do_send_keys(self,by_locator,text):
WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(by_locator)).send_keys(text
Loginpage
"""
Login page actions
"""
from page_objects.base_page import Base_Page
from selenium.webdriver.common.by import By
from config import config
class Login_page(Base_Page):
"Class to run the login page"
user_name = (By.XPATH,"//input[@id='username']")
password = (By.XPATH,"//input[@id='password']")
check_box = (By.NAME,"remember")
login_button = (By.XPATH,"//input[@id='login']")
base_url = config.BASE_URL
def set_username(self):
"Set the username in the username field"
try:
username = self.do_send_keys(self.user_name,"1111111")
self.result_flag = True
except Exception as e:
self.result_flag = False
print(f"Could not set the username. Got an error {e}")
return self.result_flag
Conftest
import pytest
from selenium import webdriver
from pytest_bdd import given
@pytest.fixture(params=['Chrome','Firefox'], scope="class")
def init_driver(request):
if request.param == 'Chrome':
web_driver = webdriver.Chrome()
if request.param == 'Firefox':
web_driver = webdriver.Firefox()
request.cls_driver = web_driver
yield
web_driver.close()
@given('Navigate to the URL')
def navigate_url(init_driver):
"Pass the username"
init_driver.get("https://www.example.com")
my test file which is inside the step_defs
from pytest_bdd import given, when, then, scenario, parsers
from page_objects.base_page import Base_Page
from page_objects.login_page import Login_page
import pytest
scenario("../features/login.feature",'Login to the app')
def test_pass():
pass
@when(parsers.cfparse('Enter the username {username:Number}',extra_types=dict(Number=int)))
def get_username(init_driver):
"Set the phone number as a username"
log = Login_page(init_driver)
log.set_username()
My feature file ''' Feature: Navigate to the Practo app and Login with credentials
Scenario Outline: Login to the app Given Navigate to the URL When Enter the username '' And ENter the password And De-select the checkbox And Click the login button Then Verify we have logged into the app
When I run pytest test_file_name.py I am not getting any error but it's not starting the webdriver also ,it just gives collected 1 item and it's passed.
can someone help me how to fix this issue?
[1]: https://i.stack.imgur.com/BnA6C.png