我有几个关于Selenium RC ->VerifyTextPresent的例子:(verifyTrue(selenium.isTextPresent()));
在从Selenium运行测试时,我在页面的文本中发现了一个拼写错误,但是在通过Selenium /JUnit运行测试时没有捕捉到这个错误。
我知道我需要将方法:checkForVerificationErrors();添加到java代码中,以获得与IDE相同的结果。
例如,此代码/行(验证)-> IDE:
<tr>
<td>verifyTextPresent</td>
<td>Search results: 1 - 30 of 50</td>
<td></td>
</tr>Selenium RC/JUnit:verifyTrue(selenium.isTextPresent("Search results: 1 - 30 of 50"));
在我添加了checkForVerificationErrors();方法之后,Selenium作为IDE工作。
以下是完整的代码:
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.regex.Pattern;
public class Dice_Search extends SeleneseTestCase {
private Selenium selenium;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.dice.com/");
selenium.setSpeed("2000");
selenium.start();
selenium.windowMaximize();
selenium.windowFocus();
}
@Test
public void testDice_Search() throws Exception {
selenium.open("/");
selenium.type("id=FREE_TEXT", "selenium");
selenium.type("id=zipCodeCity", "Los Angeles, CA");
selenium.click("id=searchSubmit");
selenium.waitForPageToLoad("30000");
verifyTrue(selenium.isTextPresent("Search results: 1 - 30 of 50"));
verifyTrue(selenium.isTextPresent("Create Search Agent Matching These Results"));
verifyTrue(selenium.isTextPresent("selenium"));
verifyEquals("selenium", selenium.getText("css=div.undoLabel"));
checkForVerificationErrors();
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}现在的问题是:
见以下截图:


谢谢!祝您今天愉快!
发布于 2013-08-29 15:08:43
我对RC不是很在行,但我的想法是: 1.我不明白为什么要使用verifyTextPresent --更好的解决方案是找到所需的确切元素,并检查元素中的文本?(类似于: verifyTrue(element.getText().equals("text")) 2.读取堆栈跟踪信息,如果使用Eclipse,可以单击控制台选项卡中的链接
https://stackoverflow.com/questions/15221406
复制相似问题