我用Selenium IDE创建了一个自动化测试案例。我想为该案例创建一些循环/控制流程,因此我决定将其导出到类似于Java的东西中(我最熟悉Java)。我导出到了Java/JUnit4/Web Driver。我认为通过Eclipse尝试执行java文件是最好的方法,但如果有更简单的方法,请告诉我。无论如何,我找不到关于如何通过Eclipse执行此Java的好的解释。
大多数我读到的东西都告诉我要确保我的Build Path库包括Selenium Standalone Server。几乎所有我读到的东西都告诉我要使用Selenium Remote Control。然而,我认为RC已经过时了,我想知道是否有任何方法使其与我从Selenium下载的更近期的Web Driver stuff一起工作。此外,大多数我读到的东西都告诉我需要使用public static void main(),这有点棘手,因为我不知道如何修改导出的selenium给我的代码(显然我不能只将它全部粘贴到主方法中)。
如果有人能够从Selenium导出到Java再执行代码,我将永远感激不尽。
Selenium给我的代码: package com.example.tests;
这让我产生了4个错误(其中3个是注释的错误,我可以删除它们,另一个是
谢谢!
大多数我读到的东西都告诉我要确保我的Build Path库包括Selenium Standalone Server。几乎所有我读到的东西都告诉我要使用Selenium Remote Control。然而,我认为RC已经过时了,我想知道是否有任何方法使其与我从Selenium下载的更近期的Web Driver stuff一起工作。此外,大多数我读到的东西都告诉我需要使用public static void main(),这有点棘手,因为我不知道如何修改导出的selenium给我的代码(显然我不能只将它全部粘贴到主方法中)。
如果有人能够从Selenium导出到Java再执行代码,我将永远感激不尽。
Selenium给我的代码: package com.example.tests;
package com.rackspace;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class RackspaceContactAutomation {
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://cp.rackspace.com/Exchange/Mail/Contacts/List.aspx?selectedDomain=blahblahblah.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testContactAutomationJava() throws Exception {
driver.get(baseUrl + "/Exchange/Mail/Contacts/List.aspx?selectedDomain=blahblahblah.com");
driver.findElement(By.linkText("Mr. Man")).click();
driver.findElement(By.linkText("Contact Information")).click();
new Select(driver.findElement(By.id("PhoneNumberType"))).selectByVisibleText("Mobile");
driver.findElement(By.id("MobilePhone")).sendKeys("999-999-9999");
new Select(driver.findElement(By.id("PhoneNumberType"))).selectByVisibleText("Fax");
driver.findElement(By.id("Fax")).sendKeys("999-999-9999");
driver.findElement(By.cssSelector("button.primary")).click();
}
@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 boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
这让我产生了4个错误(其中3个是注释的错误,我可以删除它们,另一个是
tearDown()
方法中的fail
。我关心的不是这些错误,而是如何使这段代码真正执行?谢谢!