0
有一点噩梦,使用Scirocco来记录一个宏来测试Selenium,现在不能为我终生弄清楚如何运行它。junit并从命令行运行硒测试
要管理编译代码,我用 - classpath .:/usr/share/junit4/lib/junit.jar:/usr/local/share/selenium-2.45.0/selenium-java-2.45.0.jar
这似乎加载所需和编译所有。 测试脚本它自我:
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test1 extends TestCase {
private WebDriver driver;
private String baseUrl;
@Before
public void setUp() throws Exception {
// Download chromedriver (http://code.google.com/p/chromedriver/downloads/list)
System.setProperty("webdriver.chrome.driver", "/usr/sbin/chromedriver");
driver = new ChromeDriver();
baseUrl = "https://www.google.co.uk/?gfe_rd=cr&ei=E4syVcSOK-jN7AbK0YH4Dg&gws_rd=ssl#q=Bengt+Bjorkberg";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.name("btnG")).click();
driver.findElement(By.linkText("Ben Bjorkberg | LinkedIn")).click();
driver.findElement(By.linkText("View Ben's Full Profile")).click();
driver.findElement(By.linkText("View Ben's Full Profile")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
编译很好,理论上应该工作。
然后,我创建了以下测试运行:
package de.vogella.junit.first;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class MyTestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(Test1.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
}
但是,如果我跑
javac -classpath .:/usr/share/junit4/lib/junit.jar:/usr/local/share/selenium-2.45.0/selenium-java-2.45.0.jar MyTestRunner.java
在这一点上,我得到
MyTestRunner.java:10: error: cannot find symbol
Result result = JUnitCore.runClasses(Test1.class);
^
symbol: class Test1
location: class MyTestRunner
1 error
任何提示吗?
为什么你甚至需要'MyTestRunner'?难道你不能只使用'JUnitCore'作为主类,并且通过'de.vogella.junit.first.Test1'作为第一个参数吗?另外,你可以在'Test.java'中包含package语句并描述你的目录结构吗? – NamshubWriter
顺便说一句,JUnit4风格的测试不应该直接或间接地扩展'junit.framework.TestCase'。如果你这样做,有可能你的'@ Before'和'@ After'方法不会被调用。如果你想在你的测试中使用断言,你可以从'org.junit.Assert'静态导入方法 – NamshubWriter