当前位置: 首页 > 知识库问答 >
问题:

转发新会话时出错:尝试使用远程Webdriver在Python中运行Selenium Grid时找不到功能

凤柏
2023-03-14

我正在尝试修改现有的Selenium Pytest页面对象模型设置方法,以调用Ip上的Selenium网格。”http://localhost:4444/wd/hub".

然而,当我尝试运行我的测试类时,我收到了一个错误,转发新会话时找不到:功能异常。请查看以下代码:

conftest.py

import options as options
import pytest
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from webdriver_manager.chrome import ChromeDriverManager

selenium_grid_url = "http://192.168.1.8:4444/wd/hub"

@pytest.fixture()
def setup():
    # if browser=='chrome':
    #     driver=webdriver.Chrome(ChromeDriverManager().install())
    # else:
    #     driver=webdriver.Ie()

    dc = DesiredCapabilities.CHROME
    dc['platform'] = "WIN10"
    dc['version'] = '89'

    options = webdriver.ChromeOptions()


    driver = webdriver.Remote(desired_capabilities=dc,
                              command_executor=selenium_grid_url, options=options)
    return driver

#
# def pytest_addoption(parser):   # This will get browser value from Command Line
#     parser.addoption("--browser")
#
# @pytest.fixture()
# def browser(request):  # This will return the Browser value to setup method
#     return request.config.getoption("--browser")


##############----------------PyTest HTML Report--------------###########################

# It is hook for Adding Environment info to HTML Report
def pytest_configure(config):
    config._metadata['Project Name'] = 'nop Commerce'
    config._metadata['Module Name'] = 'Customers'
    config._metadata['Tester'] = 'Ishan'

# It is hook for delete/Modify Environment info to HTML Report
@pytest.mark.optionalhook
def pytest_metadata(metadata):
    metadata.pop("JAVA_HOME", None)
    metadata.pop("Plugins", None)

页面类:LoginPage.py

import time

from selenium import webdriver


class LoginPage:
    textbox_username_id="Email"
    textbox_password_id="Password"
    button_login_xpath="//input[@class='button-1 login-button']"
    link_logout_linktext="Logout"

    def __init__(self,driver):
        self.driver=driver


    def setUserName(self,username):
        self.driver.find_element_by_id(self.textbox_username_id).clear()
        self.driver.find_element_by_id(self.textbox_username_id).send_keys(username)

    def setPassword(self,password):
        self.driver.find_element_by_id(self.textbox_password_id).clear()
        self.driver.find_element_by_id(self.textbox_password_id).send_keys(password)
        time.sleep(10)

    def clickLogin(self):
        self.driver.find_element_by_xpath(self.button_login_xpath).click()


    def clickLogout(self):
        self.driver.find_element_by_link_text(self.link_logout_linktext).click()

我的pytest测试文件:-test_login.py

import pytest
from selenium import webdriver
from pageObjects.LoginPage import LoginPage
from utilities.readProperties import ReadConfig
from utilities.customLogger import LogGen

class Test_001_Login:
    baseURL = ReadConfig.getApplicationURL()
    username = ReadConfig.getUsername()
    password = ReadConfig.getPassword()
    logger= LogGen.loggen()

    @pytest.mark.sanity
    @pytest.mark.regression
    def test_homePageTitle(self, setup):
        self.logger.info("*******************Test_001_Login***********************")
        self.logger.info("*******************Verifying Home Page Title***********************")

        self.driver = setup
        self.driver.maximize_window()
        self.driver.get(self.baseURL)
        act_title = self.driver.title
        if act_title == "Your store. Login":
            assert True
            self.logger.info('*******************Test Passed - HomePageTitle***********************')
            self.driver.close()

        else:
            self.driver.save_screenshot("D:\\Python Programs\\SeleniumPavanSDET\\NopCommerce\Screenshots\\" + "test_homePageTitle.png")
            self.driver.close()
            self.logger.error('*******************Test Failed - HomePageTitle***********************')
            assert False

    @pytest.mark.sanity
    @pytest.mark.regression
    def test_login(self,setup):
        self.logger.info('*******************Test_001_Login***********************')
        self.logger.info('*******************Verifying Login Test**********************')
        self.driver = setup
        self.driver.maximize_window()
        self.driver.get(self.baseURL)
        self.lp = LoginPage(self.driver)
        self.lp.setUserName(self.username)
        self.lp.setPassword(self.password)
        self.lp.clickLogin()

        act_title = self.driver.title


        if act_title == "Dashboard / nopCommerce administration":
            assert True
            self.logger.info('*******************Test Passed - TestLogin***********************')
            self.driver.close()


        else:
            self.driver.save_screenshot("D:\\Python Programs\\Selenium\\NopCommerce\Screenshots\\"+"test_login.png")
            self.driver.close()
            self.logger.error('*******************Test Failed - TestLogin***********************')
            assert False

例外:-

>       driver = webdriver.Remote(desired_capabilities=dc,
                                  command_executor=selenium_grid_url, options=options)

E       selenium.common.exceptions.WebDriverException: Message: Error forwarding the new session cannot find : Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, platform: WIN10, version: 89}
E       Stacktrace:
E           at org.openqa.grid.web.servlet.handler.RequestHandler.process (RequestHandler.java:118)
E           at org.openqa.grid.web.servlet.DriverServlet.process (DriverServlet.java:85)
E           at org.openqa.grid.web.servlet.DriverServlet.doPost (DriverServlet.java:69)
E           at javax.servlet.http.HttpServlet.service (HttpServlet.java:707)
E           at javax.servlet.http.HttpServlet.service (HttpServlet.java:790)
E           at org.seleniumhq.jetty9.servlet.ServletHolder.handle (ServletHolder.java:865)
E           at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle (ServletHandler.java:535)
E           at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle (ScopedHandler.java:146)
E           at org.seleniumhq.jetty9.security.SecurityHandler.handle (SecurityHandler.java:548)
E           at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle (HandlerWrapper.java:132)
E           at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:257)
E           at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle (SessionHandler.java:1595)
E           at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:255)
E           at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle (ContextHandler.java:1340)
E           at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope (ScopedHandler.java:203)
E           at org.seleniumhq.jetty9.servlet.ServletHandler.doScope (ServletHandler.java:473)
E           at org.seleniumhq.jetty9.server.session.SessionHandler.doScope (SessionHandler.java:1564)
E           at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope (ScopedHandler.java:201)
E           at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope (ContextHandler.java:1242)
E           at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle (ScopedHandler.java:144)
E           at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle (HandlerWrapper.java:132)
E           at org.seleniumhq.jetty9.server.Server.handle (Server.java:503)
E           at org.seleniumhq.jetty9.server.HttpChannel.handle (HttpChannel.java:364)
E           at org.seleniumhq.jetty9.server.HttpConnection.onFillable (HttpConnection.java:260)
E           at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded (AbstractConnection.java:305)
E           at org.seleniumhq.jetty9.io.FillInterest.fillable (FillInterest.java:103)
E           at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run (ChannelEndPoint.java:118)
E           at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.runTask (EatWhatYouKill.java:333)
E           at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce (EatWhatYouKill.java:310)
E           at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.tryProduce (EatWhatYouKill.java:168)
E           at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run (EatWhatYouKill.java:126)
E           at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run (ReservedThreadExecutor.java:366)
E           at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:765)
E           at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run (QueuedThreadPool.java:683)
E           at java.lang.Thread.run (None:-1)

不确定为什么会出现此错误。我已经将我的selenium服务器注册为hub,并注册了相应的节点。

如果有人能告诉我为什么会发生这个错误,那就太好了。谢谢你。

共有1个答案

宰父淳
2023-03-14
selenium_grid_url = "http://localhost:4444/wd/hub"


@pytest.fixture()
def setup():
    dc = DesiredCapabilities.CHROME
    options = webdriver.ChromeOptions()

    driver = webdriver.Remote(desired_capabilities=dc,
                              command_executor=selenium_grid_url, options=options)
    return driver

顺便问一下,如何启动selenium网格,比如独立服务器?例如:

java -jar selenium-server-standalone-3.141.59.jar
 类似资料:
  • 我的selenium配置有问题。我正在尝试在iOS和Android上自动化Selenium测试。 iOS测试独立于iOS驱动程序正常运行。Android测试也在独立正常运行。 但是当我想运行iOS和Android时,我遇到了问题! 对于我的Android测试,我正在运行这个命令,一切都很好: 但是,当我想要集成iOS测试时,我会按照以下指南更改此命令的端口:http://selendroid.io

  • 我正在使用Selenium Grid。我最近将VM(node)更新到Windows 10,它不再工作了。以下是详细信息 我通过以下方式将此VM Win10注册为网格节点: (这之前与VM Win8一起工作得很好)我可以在网格上看到这个VM Win10注册了3个浏览器IE11、FF和Chrome 在我的代码中,我通过以下方式创建web驱动程序: 我总是得到这个错误当我执行测试 转发新会话时出错,无法

  • 我最近安装了一个用于开发测试的selenium网格环境。然而,我们面临以下错误: 转发新会话时出错,无法找到:功能{browserName:chrome,chromeOptions:{args:[--headless,--no sandbox],二进制:,首选项:{plugins.always\u open\u pdf\u externally:true},w3c:false},loggingPr

  • 当我尝试在Chrome中运行测试时,出现以下错误: 初始化方法AutomationUsingSelenium。蓝绿色。MyTestInitialize引发异常。OpenQA。硒。DriversServiceNotFoundException:OpenQA。硒。DriversServiceNotFoundException 原因是什么?

  • 问题内容: 我从这里选择了最新的2.45.0 。遵循文档并使用以下命令启动集线器 并且,文件内容为: 而且,唯一的 到目前为止,一切看起来都很不错。在这里注册后,请查看控制台的屏幕截图 而且,当我尝试通过以下方式开始测试时,问题就开始了: 而且,它抛出: WebDriver.dll中发生类型’System.InvalidOperationException’的异常,但未在用户代码中处理 附加信息:

  • 我使用了最新的Selenium服务器,从这里开始是2.45.0。遵循文档并使用以下命令启动中心 并且,JSon文件内容是: 并且,唯一具有 在这之前,一切看起来都很好。在此处注册后,请查看控制台的屏幕截图 而且,当我试图开始测试时,问题就开始了: 它抛出: “系统”类型的例外。WebDriver中发生“InvalidOperationException”。dll,但未在用户代码中处理 附加信息:无