Whenever I run my code, the chrome opens and quickly closes, I observed the chrome browser and when it opens it does not even go the the URL link, it opens and then quickly closes for like a milli-second.
If I remove the Given/When/Then along with the “def” it runs smoothly. I’m wondering what might be the problem when I use Given/When/Then?
Code is written on Python language via Visual Studio code
VS code does not display errors and there is no errors displayed on the terminal as well.
from behave import *
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
service = Service(executable_path="chromedriver.exe")
driver = webdriver.Chrome(service=service)
@given('User accesses website')
def accessWebsite(context):
driver.get("<website URL here")
@when('User enters valid registered email')
def enterUsername(context):
driver.find_element(By.ID, "username").send_keys("[email protected]")
@when('User enters valid registered password')
def enterPassword(context):
driver.find_element(By.XPATH, '//*[@id="root"]/div/div/div/div[2]/div/div/div/div[2]/form/div/div[2]/div/div/div[1]/input').send_keys("ABc123$%")
@when('User presses Login button')
def pressEnter(context):
driver.find_element(By.XPATH, '//*[@id="root"]/div/div/div/div[2]/div/div/div/div[2]/form/div/div[3]/button').click()
@then('User is redirected to website main page')
def verifyWorkspacesHeader(context):
driver.implicitly_wait(10)
driver.find_element(By.XPATH, '//*[@id="root"]/div/div[2]/div[1]/p')
def after_all(context):
time.sleep(10)
driver.quit()
I tried removing Given/When/Then along with “def” and the steps run smoothly, so I assume that the webdriver location is not the problem.
I’m trying to automate the website with Behave since I also want to integrate it with Allure reports.
Angel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.