【问题标题】:Run a selenium test in saucelabs Windows7在 saucelabs Windows7 中运行硒测试
【发布时间】:2015-01-09 02:03:19
【问题描述】:

我正在尝试运行一个简单的测试,看看我是否可以使用以下功能运行。

OS: Windows 7
Browser: Firefox
Browser Version: 33

这是我的代码:

import static org.junit.Assert.*;

import java.net.URL;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class Tests {

    private WebDriver driver;

    @Before
    public void setUp() throws Exception {
        // Choose the browser, version, and platform to test
        DesiredCapabilities caps = DesiredCapabilities.firefox();
        caps.setCapability("platform", "Windows 7");
        caps.setCapability("version", "33");
        caps.setCapability("browserName", "");
        // Create the connection to Sauce Labs to run the tests
        this.driver = new RemoteWebDriver(
                new URL("http://<axxxxxx>:<5xxxxx@ondemand.saucelabs.com:80/wd/hub"),
                caps);
    }

    @Test
    public void webDriver() throws Exception {
        // Make the browser get the page and check its title
        driver.get("http://www.amazon.com/");
        assertEquals("Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more", driver.getTitle());
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
    }
}

当我运行此测试时,我似乎无法使用 Windows 7:

java.lang.IllegalArgumentException: No enum constant org.openqa.selenium.Platform.Windows 7
    at java.lang.Enum.valueOf(Enum.java:236)
    at org.openqa.selenium.Platform.valueOf(Platform.java:30)
    at org.openqa.selenium.remote.DesiredCapabilities.setCapability(DesiredCapabilities.java:168)

我很困惑。网站http://docs.seleniumhq.org/about/platforms.jsp 表示支持 Windows 7。我在哪里做错了?

【问题讨论】:

  • 你可以尝试在 setCapability 中使用Platform.WINDOWS 吗?
  • 您使用的是什么版本的 Selenium?如果您使用 2.43.0,这是 Sauce Labs 列出的支持的最新版本,它可以工作吗?
  • 看来我需要说平台为VISTA,然后它在Windows7上运行。DesiredCapabilities能力= DesiredCapabilities.firefox();能力.setCapability(“版本”,“33”);能力.setCapability(“平台”,Platform.VISTA); capabilities.setCapability("name", "Windows7Firefox33");
  • @VivekSingh,如果我尝试了该选项。如果我说 Platform.WINDOWS,它将在哪个 Windows 操作系统中运行。当我尝试这个时,默认情况下它使用的是 XP。我希望我的测试在 Windows 7 上运行。
  • @Louis,我使用的是 2.44.0 硒。但是,我不得不将平台设为“VISTA”。现在它可以在 Windows7 上运行

标签: selenium-webdriver saucelabs


【解决方案1】:

您遇到了Selenium 2.44.0 中的错误。正如 Sauce Labs 知识库中的 this article 所指出的,您有两种选择:

  1. 根据文章的首选选项是恢复到 2.43.0。

  2. 您选择的选项:使用 Platform 枚举中的值之一,而不是 String。 (事实证明,至少在一段时间内无法使用此选项,但 Sauce Labs 的人们修改了他们的最终允许它。)

文章还指出,下一版本的 Selenium 将进行必要的修复。

【讨论】:

【解决方案2】:

如下定义功能解决了我的问题。在平台上观察 VISTA。

DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 
capabilities.setCapability("version", "33"); 
capabilities.setCapability("platform", Platform.VISTA); 
capabilities.setCapability("name", "Windows7Firefox33");

【讨论】:

    猜你喜欢
    • 2014-07-22
    • 2016-05-07
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2017-02-10
    • 1970-01-01
    • 2014-08-24
    • 2013-06-30
    相关资源
    最近更新 更多