【问题标题】:JSONOBject hash not found未找到 JSONOBject 哈希
【发布时间】:2017-05-18 05:20:39
【问题描述】:

我正在使用 JAVA 和 Selenium WebDriver 编写测试自动化脚本, 我的测试在云环境(crossbrowsertesting.com)上运行。 有一个功能可以拍摄浏览器窗口的快照, 当我使用 RemoteWebDriver 时,这行代码工作正常,但需要用 WebDriver 替换它,因为无法获得 windowHandles。 但我现在收到以下错误,说明 "方法 getSessionId() 未为 WebDriver 类型定义"

snapshotHash=myTest.takeSnapshot(driver.getSessionId().toString());

//拍摄快照方法:

public String takeSnapshot(String seleniumTestId) throws UnirestException {
        System.out.println("Screen Shots Taken.");

        /*
         * Takes a snapshot of the screen for the specified test.
         * The output of this function can be used as a parameter for setDescription()
         */
        HttpResponse<JsonNode> response = Unirest.post("http://crossbrowsertesting.com/api/v3/selenium/{seleniumTestId}/snapshots")
                .basicAuth(username, api_key)
                .routeParam("seleniumTestId", seleniumTestId)
                .asJson(); 
        // grab out the snapshot "hash" from the response
         snapshotHash = (String) response.getBody().getObject().get("hash");

        return snapshotHash;
    }

【问题讨论】:

    标签: selenium selenium-webdriver selenium-grid2


    【解决方案1】:

    我不太明白为什么需要使用“WebDriver”代替“RemoteWebDriver”? “RemoteWebDriver”是所有 Web 驱动程序实现之母,它应该足以与任何远程网格环境一起工作。我不明白为什么您需要切换到使用“WebDriver”参考,这是“RemoteWebDriver”实现的接口之一。 getSessionId() 不是任何接口规范的一部分,而是RemoteWebDriver 提供的直接实现。

    getWindowHandles()WebDriver 接口规范的一部分,您应该仍然可以使用它。

    【讨论】:

      猜你喜欢
      • 2012-08-02
      • 1970-01-01
      • 2019-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多