如何把Selenium script转换成 Java Ruby代码 ( how to convert selenium script to Java/Ruby code )

访问量: 1458

In short :  open selenium IDE => File => Export TestCase as ... =>  Junit4 code / Ruby code

1. 写好test case in selenium IDE
2. export them as java/junit4 scripts.
3. create a maven project.
4. $ mvn test
5. 针对里面的ERROR,修改:

 23     @Test
 24     public void shouldRun() throws Exception {
 25         driver.get(baseUrl + "jquery/test_case_should_omit_blanks_for_the_field_name_in_rules.html");
 26         // no input at all
 27         driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
 28         WebElement element = driver.findElement(By.cssSelector("#rsvErrors"));
 29         // ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
 30         assertEquals(false, element.getText().contains("Please enter your first name."));
 31         // let's input all the fields.
 32         driver.findElement(By.name("first_name")).clear();
 33         driver.findElement(By.name("first_name")).sendKeys("Jim");
 34         driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
 35         // ERROR: Caught exception [ERROR: Unsupported command [getAlert]]
 36     }   

最后,发现 selenium 导出的代码,并不能100%跟原来的一致,例如 verifyTextPresent, 这个方法在java代码中就没有,所以,可以写一个。。。

 66     protected void verifyTextPresent(String expected){
 67         WebElement body = driver.findElement(By.cssSelector("body"));
 68         assertEquals(true, body.getText().contains(expected));
 69     }

订阅/RSS Feed

Subscribe

分类/category