硒:尝试使用硒网格在多个浏览器上运行测试

硒:尝试使用硒网格在多个浏览器上运行测试

问题描述:

enter image description here我运行硒ID这3次测试,硒:尝试使用硒网格在多个浏览器上运行测试

enter image description here

,但我想并行运行这些测试在不同的浏览器,用于我试图使用Selenium Grid和参照此http://code.google.com/p/selenium/wiki/Grid2

对此,我使用此代码

    public class testjava extends SeleneseTestCase { 
@Before 
public void setUp() throws Exception { 
    selenium = new DefaultSelenium("localhost", 4444, "*chrome", "www.yahoo.com/"); 
    selenium.start(); 
} 

@Test 
public void testTestjava() throws Exception { 
} 

@After 
public void tearDown() throws Exception { 
    selenium.stop(); 
} 

}

,但我得到这个例外

   java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V 
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:57) 
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:47) 
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:211) 
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:102) 
at com.selenium.testjava.setUp(testjava.java:20) 
at junit.framework.TestCase.runBare(TestCase.java:128) 
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:230) 
at junit.framework.TestResult$1.protect(TestResult.java:110) 
at junit.framework.TestResult.runProtected(TestResult.java:128) 
at junit.framework.TestResult.run(TestResult.java:113) 
at junit.framework.TestCase.run(TestCase.java:120) 
at junit.framework.TestSuite.runTest(TestSuite.java:228) 
at junit.framework.TestSuite.run(TestSuite.java:223) 
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) 
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

感谢

的DefaultSelenium是硒1(RC)-compability。 localhost是你的RC服务器(它是selenium服务器)。

但我会建议你使用Selenium 2.就像它在你的链接说你必须做到以下几点:

DesiredCapabilities capability = DesiredCapabilities.firefox(); 
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability); //localhost is your hub here 

这是一个简单的例子,它在网格请求Firefox浏览器。你可以在任何平台上的任何指定浏览器:

capability.setBrowserName(“firefox”); 
capability.setPlatform(“LINUX”); 
capability.setVersion(“3.6”); 

而你需要您注册到这样的轮毂上的至少一个节点:

java -jar selenium-server-standalone-2.x.0.jar -role wd -hub http://localhost:4444/grid/register -browser browserName=firefox,version=3.6,platform=LINUX 

再次假设硒枢纽在本地主机上运行。我希望这有助于开始。只是问你是否还有其他问题。

+0

谢谢,我知道它非常基本的Q,但我不明白我在哪里写这段代码:DesiredCapabilities capability = DesiredCapabilities.firefox(); ?其次,我想在Firefox中运行我的测试用例之一,但在Chrome中运行其他测试用例时,我该如何处理这个问题: – junaidp 2012-02-20 08:00:19

+0

capability.setBrowserName(“firefox”);或者capability.setBrowserName(“chrome”);但是对于chrome,你需要首先在你想用chrome运行测试的机器上启动chromeserver:http://code.google.com/p/selenium/wiki/ChromeDriver – tester 2012-02-20 08:12:37

+0

谢谢,但是我的第一个问题仍然存在我会写这个代码:DesiredCapabilities capability = DesiredCapabilities.firefox();因为我使用的是硒IDE,而不是日食.. – junaidp 2012-02-20 08:27:17

您需要将JUnit 4与Selenium结合使用。

将您的JUnit 4 Selenium测试复制到Eclipse中。

写启动了Firefox的配置文件,并进一步DesiredCapabilities capability = DesiredCapabilities.firefox();@Before

启动枢纽,启动节点,运行测试。

但我建议您阅读有关JUnit 4中的JUnit 4和Selenium Testing的基本教程。 只需Google即可找到您的解决方案。

Java知识也有帮助。