[英]“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
can include verifyTrue in a condition like if 可以在诸如
(verifyTrue( sel.isTextPresent("text to search")) { .... } (verifyTrue(sel.isTextPresent(“要搜索的文本”)){....}
assertTrue
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.