简体   繁体   English

当我在Java中运行代码时,“ verifyTextPresent”给我一个错误的结果

[英]“verifyTextPresent” is giving me a wrong result when I run the code in Java

I used Selenium IDE to create a recorded test and one of the commands used was verifyTextPresent. 我使用Selenium IDE创建了一个记录的测试,并且使用的命令之一是verifyTextPresent。 The IDE says there is an error if the text is changed (which is what is expected). IDE指出,如果更改了文本(这是预期的),则会出现错误。

I put the recorded test into Eclipse and ran it, the results says it passed. 我将记录的测试放入Eclipse,然后运行它,结果表明它已通过。

Now I have put in different values and never changed the values in my code, but eclipse says it runs fine with no errors. 现在,我输入了不同的值,并且从未更改代码中的值,但是eclipse表示它运行正常,没有错误。 But when I run it in the IDE, it says there are errors and it highlights where the error is. 但是,当我在IDE中运行它时,它表示存在错误,并突出显示了错误所在。

How come it does not fail on Eclipse when different values are entered for the verifyTextPresent? 当为verifyTextPresent输入不同的值时,为什么它不会在Eclipse上失败?

Here is the code I use; 这是我使用的代码;

public class MarvinDataTest extends SeleneseTestBase
{
private Selenium selenium;
private String success = "success";

@Before
public void setUp() throws Exception 
{
    selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost:8000/");
    selenium.start();
}

@Test
public void testMarvinDataTest() throws Exception 
{
    selenium.open("/eem/api/v1/metrics/displacement/286");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/displacement/287");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/displacement/288");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    ***verifyTrue(selenium.isTextPresent("\"displacement\": 20,"));***
    selenium.open("/eem/api/v1/metrics/humidity/286");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/humidity/287");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/humidity/288");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/load/286");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/load/287");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/load/288");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    ***verifyTrue(selenium.isTextPresent("\"load\": 4,"));***
    selenium.open("/eem/api/v1/metrics/pressure/286");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/pressure/287");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/pressure/288");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/temperature/286");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/temperature/287");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/temperature/288");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    verifyTrue(selenium.isTextPresent("\"temperature\": 17"));
    selenium.open("/eem/api/v1/metrics/vibration/286");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/vibration/287");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    selenium.open("/eem/api/v1/metrics/vibration/288");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    ***verifyTrue(selenium.isTextPresent("\"vibration\": 4"));***
    selenium.open("/eem/api/v1/metrics");
    assertEquals("", selenium.getTitle());
    verifyTrue(selenium.isTextPresent("success"));
    verifyTrue(selenium.isTextPresent("mm"));
    verifyTrue(selenium.isTextPresent("%"));
    verifyTrue(selenium.isTextPresent("kg"));
    verifyTrue(selenium.isTextPresent("N/m"));
    verifyTrue(selenium.isTextPresent("C"));
    verifyTrue(selenium.isTextPresent("G"));
    selenium.addScript("", "");     
}

@After
public void tearDown() throws Exception 
{
    selenium.stop();
}
}

The lines with the asterisks have the wrong data in it and should show up false. 带星号的行中的数据有误,应显示为false。 It shows an error when using the IDE but when using Eclipse it says it has passed with no errors. 使用IDE时会显示错误,但是使用Eclipse时它表示已通过且没有错误。

Can somebody please explain this and help me with finding a solution? 有人可以解释一下并帮助我找到解决方案吗?

I noticed you've tried giving incorrect values using only verifyTrue , this actually wont fail a step...You can use assertTrue for this purpose.. 我注意到您尝试仅使用verifyTrue给出错误的值,但这实际上不会失败...您可以为此使用assertTrue

verifyTrue

  • is a part of the SeleneseTestCase class and is a SeleniumAPI 是SeleneseTestCase类的一部分,是SeleniumAPI
  • will not fail the test step where you are calling VerifyTrue 不会在您调用VerifyTrue的测试步骤中失败
  • can include verifyTrue in a condition like if 可以在诸如

    (verifyTrue( sel.isTextPresent("text to search")) { .... } (verifyTrue(sel.isTextPresent(“要搜索的文本”)){....}

assertTrue

  • part of JUnit API JUnit API的一部分
  • the test step will fail if an assertion fails 如果断言失败,则测试步骤将失败
  • cannot be included in any other command 不能包含在任何其他命令中

I found out how to make the test fail when it runs on eclipse. 我发现了在Eclipse上运行时如何使测试失败。 In the testMarvinDataTest method, put in the checkForVerificationErrors() method at the bottom. 在testMarvinDataTest方法中,在底部放入checkForVerificationErrors()方法。 That now fails the test and shows an error 现在测试失败,并显示错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的程序在运行时给我错误的输出? - Why is my program giving me the wrong output when I run it? 为什么当我使用带有文本的文本文件(如下所示)运行此代码时,它会给我一个 java.util.InputMismatchException - why is it giving me an java.util.InputMismatchException when i run this code when I use a text file with the text (shown underneath) 为什么我的Java Morse代码翻译器给我错误的输出? - Why is my Java Morse Code translator giving me the wrong output? 当我尝试在Java中运行以下二进制搜索代码时,它将引发ArrayOutOfExcepetion。 谁能看看我告诉我哪里出了问题? - When i try to run the below Binary Search code in java, it throws ArrayOutOfExcepetion. Can any anyone have a look and tell me where I went wrong? 当我将Java代码转移到有关连接到服务器并获得结果的iOS代码时,怎么了? - What's wrong when i transfer the java code to iOS code about connecting to the server and get result? Java中的字符串字反转给出了错误的结果? - String word reverse in Java giving wrong result? Java ArrayList 子列表给出错误的结果 - Java ArrayList sublist giving wrong result 奇怪的JAVA日期格式给出错误的结果 - Weird JAVA date formatting giving wrong result 签名和验证数据在Java中给出了错误的结果 - Signing and verifying data is giving wrong result in Java Java String.matches给出了错误的结果 - Java String.matches giving wrong result
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM