pytest-selenium | Plugin for running Selenium with pytest | Functional Testing library
kandi X-RAY | pytest-selenium Summary
kandi X-RAY | pytest-selenium Summary
Plugin for running Selenium with pytest
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of pytest-selenium
pytest-selenium Key Features
pytest-selenium Examples and Code Snippets
volumes:
data-volume:
download-volume:
external: true
name: selenium_downloads
cd path/to/current/directory &
virtualenv env &
"cmd.exe" "\c .env/Scripts/Activte && pip install -r
requirements.txt && pytes your commands to trigger script
here"
# Find Element using Xpath
element = driver.find_element_by_xpath("//a[@class='btn' and @title='Submit']")
# Click on the button using Javascript Executor
driver.execute_script("arguments[0].click();", element)
$ pytest -p no:logging ...
[tool.pytest.ini_options]
addopts = "-p no:logging"
[pytest]
addopts = -p no:logging
[tool.pytest.ini_options]
log_file = "test.log"
log_
@pytest.fixture()
def create_staff_user_in_db(transactional_db):
staff_user = User.objects.create_user(...)
...
@pytest.fixture
def test_server(request) -> LiveServer:
request.getfixturevalue("transa
for i in divs:
print(i.location)
textElements = driver.find_elements_by_xpath("//body//*[text()]") #Gets all text elements
for i in textElements:
print(i.text)
print(i.location)
def screenshot_dec(func):
def wrapper(selenium):
try:
func(selenium)
except:
selenium.save_screenshot("error_{0}.png".format(func.__name__))
raise
return wrapper
@screenshot_dec
conftest.py
@fixture
def selenium():
# pytest-selenium provides this fixture & you can override it if required.
return selenium
@fixture
def home(selenium):
#do login
return HomePage
login.p
# urls.py
from django.urls import path
from django.views.debug import default_urlconf
urlpatterns = [
path('', default_urlconf, name='index'),
]
import sys
for arg in sys.argv:
print(arg)
print ("email:" + sys.argv[2])
print ("password:" + sys.argv[3])
from selenium import webdriver
import pytest
import sys
def test_login(specifiedEmail, specifiedPW):
Community Discussions
Trending Discussions on pytest-selenium
QUESTION
I'm getting desperate because I can't seem to find a solution for what I thought would be used by everyone out there.
I want to test a simple login with selenium and pytest with a live_server url. According to pytest-django doc, a simple fixture called live_server
should do the trick (https://pytest-django.readthedocs.io/en/latest/helpers.html#live-server).
Unfortunately when I pass this fixture to my test and try to visit my website with it I get:
localhost refused to connect
for example for this:
...ANSWER
Answered 2020-Mar-30 at 08:27Turning the comment into an answer: by default, the tests avoid running db queries to not to slow down the test run, so User.objects.create_user
doesn't write to database. To ensure db commits, use the @pytest.mark.django_db(transaction=True)
marker in tests or the transactional_db
fixture in your fixtures:
QUESTION
I would like to use pytest
, pytest-django
, and pytest-selenium
together to test my Django application functionality. If I start the server manually with python manage.py runserver
, and manually input the URL, it works fine.
The live_server
fixture from pytest-django
is supposed to start a server process in the background that I could use, but it's not working. Instead of a passing test, I get "The requested resource was not found on this server."
Here are the relevant sections of my files:
pytest.ini
...ANSWER
Answered 2019-Jun-30 at 08:22If you are testing against the default index page (the one with the "The install worked successfully! Congratulations!" greeting), it is only shown when running the development server with DEBUG = True
. In particular, it won't be present in tests. If you want to use the view, you need to explicitly configure it in urls
module like the other views:
QUESTION
How to restart(relaunch) test after failure(fail)?
I've test ci_events_page.py (pytest-selenium test)
yml settings(.gitlab-ci.yml):
...ANSWER
Answered 2018-Feb-07 at 14:22You can use the retry option. This will retry the job x times.
Retry job 2 times:
..retry value has to be a positive integer, equal or larger than 0, but lower or equal to 2 (two retries maximum, three runs in total).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pytest-selenium
You can use pytest-selenium like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page