我是新来的-bdd。我必须从头开始实现自动化框架。所以我遵循了一些材料,用小的框架实现了非常基本的。当我运行测试时,我可以看到webdriver根本没有启动,也没有看到任何错误。我不知道如何解决这个问题。有人能帮我解决这个问题的根本原因吗?我需要一些pytest-bdd页面对象模型实现的例子?
**我的项目结构**
在测试目录中,我有一些特性,step_def目录也在那里。在steps_def中,我有一个test_file_name.py,init文件就在那里。
在页面对象目录中,我有basepage和loginpage python文件。
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登录页
"""
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_flagConftest
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")我的测试文件,在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()我的特性文件‘特性:导航到Practo应用程序和带凭证的登录
场景大纲:登录到给定的应用程序,在输入用户名'‘时导航到Enter,然后取消选中复选框并单击登录按钮,然后验证我们已登录应用程序
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发布于 2022-01-21 04:22:34
from selenium import webdriver
driver = webdriver.Firefox(executable_path = "Path to geckodriver")
driver.get("https://google.com")
time.sleep(10)
driver.close()https://stackoverflow.com/questions/70784480
复制相似问题