首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium RC verifyTrue(selenium.isTextPresent(“string”))

Selenium RC verifyTrue(selenium.isTextPresent(“string”))
EN

Stack Overflow用户
提问于 2013-03-05 10:25:39
回答 1查看 5.8K关注 0票数 3

我有几个关于Selenium RC ->VerifyTextPresent的例子:(verifyTrue(selenium.isTextPresent()));

在从Selenium运行测试时,我在页面的文本中发现了一个拼写错误,但是在通过Selenium /JUnit运行测试时没有捕捉到这个错误。

我知道我需要将方法:checkForVerificationErrors();添加到java代码中,以获得与IDE相同的结果。

例如,此代码/行(验证)-> IDE:

代码语言:javascript
复制
<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工作。

以下是完整的代码:

代码语言:javascript
复制
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();
    }
}

现在的问题是:

  1. 如何更好地添加checkForVerificationErrors();在每个(verifyTrue(selenium.isTextPresent()之后添加;行或可以在测试结束时添加(如上面的代码)?
  2. 我如何知道Selenium RC/JUnit中的哪一行测试失败了?在Log窗口的Selenium中,它显示了行,命令也被标记为红色。在JUnit中,只显示故障跟踪,而不显示生成测试错误的行。

见以下截图:

谢谢!祝您今天愉快!

EN

回答 1

Stack Overflow用户

发布于 2013-08-29 15:08:43

我对RC不是很在行,但我的想法是: 1.我不明白为什么要使用verifyTextPresent --更好的解决方案是找到所需的确切元素,并检查元素中的文本?(类似于: verifyTrue(element.getText().equals("text")) 2.读取堆栈跟踪信息,如果使用Eclipse,可以单击控制台选项卡中的链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15221406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档