Junit in Eclipse can not deal with a LinkText apostrophe
A testcase runs in Selenium IDE but when exported to WebDriver and
executed in Eclipse the Junit script can not find a LinkText element with
an apostrophe in the name.
I escaped the apostrophe but still Junit can not find it.
The line in question is highlighted in the code
I exported a Selenuim testcase that did not contain any apostrophes and I
was able to run the WebDriver Junit test in Eclipse without any issues.
I will continue using the testcases without apostrophes but it would be
great if I could figure out how to deal with special characters.
Sincerely,
Rick Doucette
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 FirstSelIDEDemo {
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://www.soastastore.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testFirstSelIDEDemo() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("Store")).click();
driver.findElement(By.linkText("Tron: Legacy")).click();
driver.findElement(By.id("product_155_submit_button")).click();
new
Select(driver.findElement(By.name("product_rating"))).selectByVisibleText("2");
driver.findElement(By.id("s")).clear();
driver.findElement(By.id("s")).sendKeys("firth");
driver.findElement(By.id("searchsubmit")).click();
*****driver.findElement(By.linkText("The King\'s
Speech")).click();*****
driver.findElement(By.name("product_rating")).click();
new
Select(driver.findElement(By.name("product_rating"))).selectByVisibleText("4");
driver.findElement(By.cssSelector("form.wpsc_product_rating >
input[type=\"submit \"]")).click();
driver.findElement(By.id("product_160_submit_button")).click();
new
Select(driver.findElement(By.name("product_rating"))).selectByVisibleText("4");
driver.findElement(By.cssSelector("form.wpsc_product_rating >
input[type=\"submit\"]")).click();
driver.findElement(By.id("product_160_submit_button")).click();
driver.findElement(By.linkText("Checkout")).click();
driver.findElement(By.cssSelector("form.adjustform.remove >
input[name=\"submit\"]")).click();
driver.findElement(By.cssSelector("span >
input[name=\"submit\"]")).click();
// Warning: assertTextPresent may require manual changes
assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*ERROR:
Please enter a username\\.[\\s\\S]*$"));
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
No comments:
Post a Comment