【发布时间】:2013-03-28 10:16:17
【问题描述】:
我知道已经有非常类似的问题,但是我是 Java/Selenium WebDriver 的初学者,最初是在 Selenium IDE 中创建的,然后将其导出为 Java / JUnit4 / WebDriver 和希望得到具体的帮助,因为我不确定我到底哪里出错了。当我作为 Java Application 运行时,我收到错误 Selection 不包含主要类型,当我作为 Java Applet 运行时,我收到错误 em>选择不包含小程序。这是我的代码:
package com.exports.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Login {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://www.example.co.uk/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testLogin() throws Exception {
driver.get(baseUrl + "/123example/index.jsp");
// ERROR: Caught exception [ERROR: Unsupported command [getEval | prompt("Username: ") | ]]
driver.findElement(By.name("LoginText1")).clear();
element.sendKeys(user input);
//driver.findElement(By.name("LoginText1")).clear();
//driver.findElement(By.name("LoginText1")).sendKeys(_username);
// ERROR: Caught exception [ERROR: Unsupported command [getEval | prompt("Password: ") | ]]
driver.findElement(By.name("password1")).clear();
element.sendKeys(user input);
//driver.findElement(By.name("password1")).clear();
//driver.findElement(By.name("password1")).sendKeys(_password);
driver.findElement(By.cssSelector("img[alt=\"Login\"]")).click();
// ERROR: Caught exception [ERROR: Unsupported command [windowFocus | | ]]
driver.switchTo().window("CarrierNet Desktop");
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alert.getText();
} finally {
acceptNextAlert = true;
}
}
}
非常感谢任何帮助。
【问题讨论】:
-
好吧,要运行它,它应该包含
public static void main(String args[])它没有的方法。要“运行”它,您必须运行 TEST。但我不知道如何在 Eclipse 中做到这一点 -
@PavelJanicek 我会在哪里添加,
public static void main(String args[])? -
@Perception 您如何将它作为 jUnit 测试运行,因为当我尝试这样做时,它要求配置它,但我不知道该放什么。
-
@D.Shah - 你是说 Eclipse 要求你配置 jUnit?你用的是什么版本的 Eclipse?
-
@Perception 我正在为 Web 开发人员运行 Eclipse Java EE IDE。版本:Juno Service Release 2。内部版本 ID:20130225-0426。几天前我从网站上下载了它。
标签: java eclipse selenium selenium-webdriver