Я пытаюсь запустить мой контрольный пример автоматизации (записан в Python) в Selenium Grid (создан с помощью файла docker -compose.yml). Когда я запускаю команду "docker -compose up -d", Grid открывается успешно и работает как положено. Тем не менее, он продолжает выдавать TimeoutException: сообщение, когда я запускаю файл test.py (я использую корпоративный ноутбук, подключенный через VPN, выпущенный моей организацией) . Если я запускаю файл test.py без DesiredCapabilities , это работает абсолютно нормально. Я использую сетку / концентратор Selenium в первый раз в моей системе (Windows 10).
Я старался изо всех сил, чтобы найти ответ в Google & stackoverflow, пока я здесь! Не могли бы вы помочь мне с вашими отзывами, где я делаю ошибку?
test.py
import time
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class TestLogin(unittest.TestCase):
def setUp(self):
base_url = "http://newtours.demoaut.com/mercurywelcome.php"
host = "http://localhost:4444/wd/hub"
caps = DesiredCapabilities.CHROME.copy()
self.driver = webdriver.Remote(command_executor=host, desired_capabilities=caps)
self.driver.maximize_window()
self.driver.get(base_url)
def test_login(self):
wait = WebDriverWait(self.driver, 10)
user_name = wait.until(ec.presence_of_element_located((By.NAME, "userName")))
user_name.send_keys('ralphsin')
print("Entered UserId")
time.sleep(2)
password = wait.until(ec.presence_of_element_located((By.NAME, "password")))
password.send_keys('abc123')
print("Entered Password")
time.sleep(2)
log_in = wait.until(ec.presence_of_element_located((By.XPATH, "//input[@alt='Sign-In']")))
log_in.click()
print("Clicked on Sign-In button!")
time.sleep(2)
def tearDown(self):
self.driver.quit()
docker -compose.yml
version: '3'
services:
hub:
image: selenium/hub:3.141.59
ports:
- 4444:4444
chrome:
image: selenium/node-chrome:3.141.59
depends_on:
- hub
environment:
- HUB_HOST=hub
- HUB_PORT=4444
firefox:
image: selenium/node-firefox:3.141.59
depends_on:
- hub
environment:
- HUB_HOST=hub
- HUB_PORT=4444
Сообщение об ошибке
C:\Users\rsingh99\Desktop\WebDevelopment_and_Automation\Selenium_Projects\test_selenium>pytest -v test.py
=========================================================================== test session starts ===========================================================================
platform win32 -- Python 3.6.1, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- c:\users\rsingh99\appdata\local\programs\python\python36\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\rsingh99\Desktop\WebDevelopment_and_Automation\Selenium_Projects\test_selenium
plugins: ordering-0.6
collected 1 item
test.py::TestLogin::test_login FAILED [100%]
================================================================================ FAILURES =================================================================================
__________________________________________________________________________ TestLogin.test_login ___________________________________________________________________________
self = <test.TestLogin testMethod=test_login>
def test_login(self):
wait = WebDriverWait(self.driver, 10)
> user_name = wait.until(ec.presence_of_element_located((By.NAME, "userName")))
test.py:22:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.support.wait.WebDriverWait (session="54f19a6e911494f8fd102e2f51cb4104")>
method = <selenium.webdriver.support.expected_conditions.presence_of_element_located object at 0x000002925F4AE4E0>, message = ''
def until(self, method, message=''):
"""Calls the method provided with the driver as an argument until the \
return value is not False."""
screen = None
stacktrace = None
end_time = time.time() + self._timeout
while True:
try:
value = method(self._driver)
if value:
return value
except self._ignored_exceptions as exc:
screen = getattr(exc, 'screen', None)
stacktrace = getattr(exc, 'stacktrace', None)
time.sleep(self._poll)
if time.time() > end_time:
break
> raise TimeoutException(message, screen, stacktrace)
E selenium.common.exceptions.TimeoutException: Message:
..\..\..\..\appdata\local\programs\python\python36\lib\site-packages\selenium\webdriver\support\wait.py:80: TimeoutException
======================================================================== 1 failed in 11.75 seconds ========================================================================