Dear Geeks
I am new to pytest. I am following a youtube channel. I am writing the same code.
learning to test login functionality of an ecommerce application
i have written testcase file. please have a look at it. while running the testcase i am getting error in the line self.driver.get(self.baseURL)
error messaeg
test_login.py:10 (Test_001_Login.test_homePageTitle)
self = <testCases.test_login.Test_001_Login object at 0x000001CC152D38E0>
it is blocking to move further learning as it is the first test
The original code ::
import pytest
from selenium import webdriver
from pageObjects.LoginPage import LoginPage
The code you shared, are they part if a class? What does that class inherit? Usually with cases like this with pytest one should create a fixture which souls contain web driver specific functionalities.
One thing though, can you ensure that you have chrome driver installed and it’s on your path? Although in that case, you would be getting more error instead of just the error you mentioned. Something like: ... selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. ... somewhere along the line.
Okay so I tried running your code and the first test passes, however, I cannot tell if LoginPage had a problem which caused it to tail as that code isn’t given here also the error message you shared seem to be blaming test_homePageTitle) which isn’t the case as it passes fine in my case. Here’s the code I tried (I omitted the other test as I don’t have the module).
from selenium import webdriver
class Test_001_Login:
baseURL = "https" + "://admin-demo.nopcommerce.com/login?ReturnUrl=%2Fadmin%2F"
password = "admin"
def test_homePageTitle(self):
self.driver = webdriver.Chrome()
self.driver.get(self.baseURL)
actual_title = self.driver.title
if actual_title == "Your store. Login":
assert True
self.driver.close()
else:
assert False
self.driver.close() # This code will be unreachable
A few things here though (Not connected to your error though). You should close the driver right after you captured the title. And then instead of separating assert True and assert False, you can add assertion for the conditional. Something like the following:
Also, if you are interested to learn PyTest, and have any question, you can ask here or DM me. It’d be good if you share the video you’re learning from, I’d be interested to see what drove them to flaunt that code in a tutorial
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status
E from unknown error: missing or invalid ‘entry.level’
E (Session info: chrome=99.0.4844.82)
E (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.19043 x86_64)
Dear Mafinar
I hardcoded the chrome path and now the test passed. I know it is not a good practice.
I have added the chromedriver path to system and also environment variable but still it is not recognise it.
please let me know how to resolve it
“’%s’ executable needs to be in PATH. %s” % (
os.path.basename(self.path), self.start_error_message)
E selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH. Please see ChromeDriver - WebDriver for Chrome
Mafinar
I ran the test in terminal it works fine without manually entering the URL path. when i run from pycharm it throws the error that i mentioned earlier
Thank you again
I have one more question
can you please explain me the syntax pytest -v -s filepath
Hello, im glad you made some progress. I know how frustrating it is when you meet a wall when you are just starting to learn.
I wonder why adding to system file is not working for you, it was for me. Unfortunately I do not use Windows for development purpose so cannot readily answer to it.
You can use a site like dpaste or pastebin to share large snippets or stacktraces and paste it here.
As for your question regarding the switches: -v is verbose, as in, you will get more detailed treatment of the your test run if you have this enabled. -s would turn capture mode on. As an example, if you have logs or prints in your test, and run the terst without -s you will not see the logs or prints, but if you have -s (or --capture=yes I guess) then you shall see those on screen.
You can test if it actually is in the PATH, if you open a cmd and type in chromedriver and hit Enter. If Starting ChromeDriver 2.15.322448 is appearing, the PATH is set appropriately and there is something else going wrong. Then try the following:
Download ChromeDriver
Then you have multiple options:
Add it to your system path
Put it in the same directory as your python script