0

我在我的应用程序中编写了一个硒样本测试用例。然后,我右键单击该文件并选择“测试文件”。它导致我该如何运行硒测试案例?

Testsuite: com.MyApp.SampleSeleniumTest 
Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.265 sec 

Testcase: warning(junit.framework.TestSuite$1): FAILED 
No tests found in com.MyApp.SampleSeleniumTest 
junit.framework.AssertionFailedError: No tests found in com.MyApp.SampleSeleniumTest 
Test com.MyApp.SampleSeleniumTest FAILED 

我的代码是

package com.MyApp; 

import com.thoughtworks.selenium.*; 
import org.junit.Test; 

public class SampleSeleniumTest extends SeleneseTestCase { 

    @Override 
    public void setUp() throws Exception { 
     setUp("http://www.google.com", "*firefox"); 
    } 

    @Test 
    public void whatever() throws Exception { 
     selenium.open("/"); 
     assertTrue(selenium.isTextPresent("Explore")); 
    } 
} 
+0

你确定你使用JUnit 4.x的?否则,你不能使用注释。 – VolkerK 2012-08-06 10:36:51

+0

是的,我正在使用JUnit 4.8.2。它的工作现在。无论如何感谢您的回复 – Prince 2012-08-06 11:21:57

回答

1

这是一种替代方法做同样的

package com.MyApp; 

import com.thoughtworks.selenium.*; 
import org.junit.*; 

public class SampleSeleniumTest extends SeleneseTestCase { 

    @Before 
    public void setUp() throws Exception { 
     selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://urlofyourApp"); 
     selenium.start(); 
    } 

    @Test 
    public void testTestRC() throws Exception { 
     selenium.open("/"); 
    assertTrue(selenium.isTextPresent("Explore")); 

    } 

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

Prashant,感谢您的回复。但仍然我得到相同的错误 – Prince 2012-08-06 09:55:34

+2

@Gnik:你正在使用netbeans,对吧?尝试命名测试方法,使其开始测试,如'testWhatever()' – 2012-08-06 10:22:12

+0

感谢Prashant。它的工作。很好的答案 – Prince 2012-08-06 11:16:11