我有關於Selenium RC的幾個問題 - > VerifyTextPresent 例如:(verifyTrue(selenium.isTextPresent()));
硒RC verifyTrue(selenium.isTextPresent(「字符串」))
我跑的時候發現,在網頁上的文字拼寫的錯誤來自Selenium IDE的測試,但是在通過Selenium RC/JUnit運行測試時未發現錯誤。
我知道我需要將方法:checkForVerificationErrors();
添加到java代碼中,以獲得與IDE中相同的結果。
例如這個碼/線(驗證) - > IDE:
<tr>
<td>verifyTextPresent</td>
<td>Search results: 1 - 30 of 50</td>
<td></td>
</tr>
硒RC/JUnit的:verifyTrue(selenium.isTextPresent("Search results: 1 - 30 of 50"));
後我添加checkForVerificationErrors();
方法,硒RC它可以作爲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();
}
}
現在的問題:
如何更好添加checkForVerificationErrors(); (verifyTrue(selenium.isTextPresent()));或者可以像上面的代碼一樣在測試結束時添加?
我如何知道Selenium RC/JUnit在哪一行測試失敗?在日誌窗口中的Selenium IDE中顯示該行,該命令也標記爲紅色。在JUnit中只顯示一個Failure Trace,而不是產生測試錯誤的那一行。
見下截圖:
謝謝! 祝您有美好的一天!