某些自动化测试使用之前/之后/测试之间的问题 我在浏览器窗口卡住,没有执行测试... 不知道为什么这样做“工作。我已经从出口Selenium IDE的一些测试,导出为Java的,编辑的东西在Eclipse中,但仍不起作用...一些自动化测试使用之前/之后/测试的问题
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 Checkimage {
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 = "http://";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testCheckimage() throws Exception {
driver.get("http://");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.linkText("sign in/up"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("login-email")).clear();
driver.findElement(By.id("login-email")).sendKeys("[email protected]");
driver.findElement(By.id("login-password")).clear();
driver.findElement(By.id("login-password")).sendKeys("mike1780");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if ("sign in".equals(driver.findElement(By.id("login-buttons-password")).getText())) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("login-buttons-password")).click();
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if ("Tester".equals(driver.findElement(By.linkText("Tester")).getText())) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.linkText("Tester")).click();
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.id("inputScoreUrl"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("inputScoreUrl")).sendKeys("http://www.sheetmusicdirect.com/scorches/smd_000001.sco");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if ("Enter a URL to a publicly accessible SCO file. No need to URL encode it, just copy and paste it in.".equals(driver.findElement(By.cssSelector("p.help-block")).getText())) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("submitScoreView")).click();
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.cssSelector("img"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
try {
assertTrue(isElementPresent(By.cssSelector("img")));
} catch (Error e) {
verificationErrors.append(e.toString());
}
}
@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;
不知道为什么,这是行不通的。我从硒IDE出口一些测试,导出为Java的,编辑的东西在Eclipse中,但仍不起作用...
我很困惑它是否是错字或其他:'if(second> = 60)fail(“timeout”);'? – 2014-09-29 11:27:58