gpt4 book ai didi

java - RemoteWebDriver 无法转换为 SikuliWebDriver

转载 作者:行者123 更新时间:2023-11-29 03:28:59 26 4
gpt4 key购买 nike

我试图在 Sauce On Demand 基础设施上运行基于 Sikuli WebDriver 的测试。但我对 RemoteWebDriver 有疑问。

我有这个 BaseSikuliWebDriver 类

package com.pitito.sikuli.base;

import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import com.pitito.core.basetests.BaseLoggingTest;
import com.pitito.selenium.webdriver.RemoteWebDriverSession;
import com.pitito.selenium.webdriver.WebDriverScreenshooter;
import com.pitito.sikuli.webdriver.SikuliFirefoxDriver;

/**
* Base class for all Sikuli WebDriver tests.
*
* @author guillem.hernandez
*/
public abstract class BaseSikuliWebDriverTest {

Map<String, Object> sauceJob = new HashMap<String, Object>();

private static SikuliFirefoxDriver sikuliDriver;

protected SikuliFirefoxDriver driver() {
return getDriver();
}

public static SikuliFirefoxDriver getDriver() {
return sikuliDriver;
}

public static void setDriver(SikuliFirefoxDriver driver) {
BaseSikuliWebDriverTest.sikuliDriver = driver;
}

@Override
@BeforeMethod(alwaysRun = true)
protected void setup(Method method, Object[] testArguments) {
super.setup(method, testArguments);
String sessionId = method.getName() + "_" + testArguments.hashCode();
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability("id", sessionId);
caps.setCapability("name", sessionId);
caps.setCapability(CapabilityType.BROWSER_NAME, "firefox");
caps.setCapability("platform", Platform.XP);
caps.setCapability("version", "21");
try {
sikuliDriver = (SikuliFirefoxDriver) new Augmenter().augment(new RemoteWebDriver(new URL("http://"
+ RemoteWebDriverSession.USER + ":" + RemoteWebDriverSession.APIKEY
+ "@ondemand.saucelabs.com:80/wd/hub"), caps));
} catch (MalformedURLException e) {
e.printStackTrace();
}
setDriver(sikuliDriver);
}

@Override
@AfterMethod(alwaysRun = true)
protected void teardown(ITestResult tr, Method method) {
if ((logger() != null) && (tr.getStatus() == ITestResult.FAILURE)) {
logUnexpectedException(tr.getThrowable());
}
super.teardown(tr, method);
sikuliDriver.quit();
}

@Override
protected void logScreenshot(String screenshotName) {
logResource(new WebDriverScreenshooter(driver(), screenshotName).getScreenshot());
}
}

我实现的测试是Sikuli WebDriver的例子,代码如下:

package com.pitito.sikuli.tests;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

import com.pitito.sikuli.base.BaseSikuliWebDriverTest;
import com.pitito.sikuli.webdriver.ImageElement;

/**
* Sikuli Firefox WebDriver Automated Test Example.
*
* @author guillem.hernandez
*/
public class SikuliGoogleCodeTest extends BaseSikuliWebDriverTest {

@Test(groups = { "ES" }, description = "Use Sikuli to search on Google Maps")
public void testSikuliWebDriverPassingExample_ES() {
verifySikuliWebDriverPassingTest();
}

private void verifySikuliWebDriverPassingTest() {
// visit Google Map
driver().get("https://maps.google.com/");

// enter "Denver, CO" as search terms
WebElement input = driver().findElement(By.id("gbqfq"));
input.sendKeys("Denver, CO");
input.sendKeys(Keys.ENTER);

ImageElement image;

// find and click on the image of the lakewood area
try {
image = driver().findImageElement(new URL("https://dl.dropbox.com/u/5104407/lakewood.png"));

image.doubleClick();

// find and click on the image of the kendrick lake area
image =
driver().findImageElement(new URL("https://dl.dropbox.com/u/5104407/kendrick_lake.png"));
image.doubleClick();

// find and click the Satellite icon to switch to the satellite view
image = driver().findImageElement(new URL("https://dl.dropbox.com/u/5104407/satellite.png"));
image.click();

// find and click the plus button to zoom in
image = driver().findImageElement(new URL("https://dl.dropbox.com/u/5104407/plus.png"));
image.click();

// find and click the link button
WebElement linkButton = driver().findElement(By.id("link"));
linkButton.click();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}

当我尝试运行测试时,我得到的错误是:

[Invoker 18958118] Invoking @BeforeMethod BaseSikuliWebDriverTest.setup(java.lang.reflect.Method, [Ljava.lang.Object;)[pri:0, instance:com.pitito.sikuli.tests.SikuliGoogleCodeTest@137008a]
Failed to invoke configuration method com.pitito.sikuli.base.BaseSikuliWebDriverTest.setup:org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByCGLIB$$52a1cf6f cannot be cast to com.pitito.sikuli.webdriver.SikuliFirefoxDriver

问题出在这里:

sikuliDriver = (SikuliFirefoxDriver) new Augmenter().augment(new RemoteWebDriver(new URL("http://"
+ RemoteWebDriverSession.USER + ":" + RemoteWebDriverSession.APIKEY
+ "@ondemand.saucelabs.com:80/wd/hub"), caps));

如何远程使用 SikuliFirefoxDriver?如何使用 SikuliFirefoxDriver 转换 RemoteWebDriver?我可以吗?

最佳答案

据我所知,Selenium Grid 服务器不具备通过其 JSON api 传递 Sikuli 命令(以及用于比较目的的二进制屏幕截图)的功能。甚至 SauceLabs 也不具备这种能力。希望有一天它会在雷达上实现。在 SauceLabs 论坛上,有人问过这个问题(我也用同样的答案回答了那个问题)。

我知道有一个正在进行的项目叫做 Marionette应该能够自动化浏览器/Firefox 菜单和 native 对话框。

关于java - RemoteWebDriver 无法转换为 SikuliWebDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19405273/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com