我正在尝试使用Selenium集线器/节点连接进行简单的Web测试。想法是在Katalon IDE中进行一些测试,然后将它们导出到python中以供节点运行。因此,我制作了第一个测试用例,将其导出到python并在独立的硒节点上运行,效果很好。
不幸的是,如果我尝试从集线器运行到该节点,则该测试将无法进行。它会在起始页面上打开节点Web浏览器,但是此后不久它崩溃了,而没有进行测试。我尝试使用Firefox和chrome,但得到的结果相同。 我对python不好,所以我很抱歉如果没有我自己没有看到的简单修复。
这是我的测试用例:
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class OKGoogle(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Remote(
command_executor = 'http://192.168.1.244:4444/wd/hub',
desired_capabilities = {
'browserName': 'firefox',
'javascriptEnabled': True
})
def test_o_k_google(self):
driver = self.driver
driver.get("https://www.google.com/")
driver.find_element_by_id("lst-ib").clear()
driver.find_element_by_id("lst-ib").send_keys("ok google")
driver.find_element_by_id("lst-ib").send_keys(Keys.ENTER)
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)=concat('Use ', '\"', 'Ok Google', '\"', ' voice searches & actions - Android - Google Search ...')])[1]/following::cite[1]").click()
def is_element_present(self, how, what):
try:
self.driver.find_element(by=how, value=what)
except NoSuchElementException as e:
return False
return True
def is_alert_present(self):
try:
self.driver.switch_to_alert()
except NoAlertPresentException as e:
return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
我得到的错误:
Traceback (most recent call last):
File "OKGoogle.py", line 25, in test_o_k_google
driver.find_element_by_id("lst-ib").clear()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 360, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
'value': value})['value']
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: [id="lst-ib"]
======================================================================
ERROR: test_o_k_google (__main__.OKGoogle)
----------------------------------------------------------------------
Traceback (most recent call last):
File "OKGoogle.py", line 53, in tearDown
self.assertEqual([], self.verificationErrors)
AttributeError: 'OKGoogle' object has no attribute 'verificationErrors'
----------------------------------------------------------------------
Ran 1 test in 10.453s
FAILED (errors=2)
非常感谢您的帮助。