2015-01-08 220 views
2

我想运行一个简单的测试,看看我是否可以使用下面的功能运行。在saucelabs中运行硒测试Windows7

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>:<[email protected]ndemand.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。我在哪里犯错误?

+0

你可以尝试setCapability中的'Platform.WINDOWS'吗? –

+0

您使用的是哪个版本的Selenium?如果您使用的是2.43.0,这是Sauce Labs支持的最新版本,它的工作原理是什么? – Louis

+0

它看起来像我需要说的平台作为VISTA,然后它运行在Windows7.DesiredCapabilities功能= DesiredCapabilities.firefox(); capabilities.setCapability(“version”,“33”); capabilities.setCapability(“platform”,Platform.VISTA);功能.setCapability(“name”,“Windows7Firefox33”); –

回答

1

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

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

你在硒2.44.0碰上错误。由于在酱实验室知识库this article指出,你有两个选择:

  1. 的首选选项根据文章还原为2.43.0。

  2. 您选择的选项:使用Platform enum中的值之一,而不是String。 (事实证明,至少有一段时间是没有可能使用此选项,但酱实验室乡亲修改其最终允许它。)

文章还指出,硒的下一个版本将有必要的修复。

+0

Selenium问题位于https://code.google.com/p/selenium/issues/detail?id=8083 –