我需要通過桌面應用程序測試網頁,我試圖使用 硒IDE,我已經成功創建測試用例,但我不是 能夠在java上執行它們。如何通過桌面應用程序使用硒測試網頁?
我一直在尋找一些有用的東西,但我找不到任何幫助。
謝謝
我需要通過桌面應用程序測試網頁,我試圖使用 硒IDE,我已經成功創建測試用例,但我不是 能夠在java上執行它們。如何通過桌面應用程序使用硒測試網頁?
我一直在尋找一些有用的東西,但我找不到任何幫助。
謝謝
爲此目的而創建的框架(用Java編寫)可以下載here或者您可以從github here中檢查項目。
這個項目的設計非常簡單,但非常有效。這種類型的框架是我對每天在生產型環境中使用的框架的解釋的「免費版本」。
在名爲SampleFunctionalTest.java
的項目中有一個示例測試。假設你遵循T的自述,你應該沒有問題入門。
下面是在這個框架中測試的樣子。
@Config(url = "http://ddavison.github.io/tests/getting-started-with-selenium.htm", browser = Browser.FIREFOX) // You are able to specify a "base url" for your test, from which you will test. You may leave `browser` blank.
public class SampleFunctionalTest extends AutomationTest {
/**
* You are able to fire this test right up and see it in action. Right click the test() method, and click "Run As... jUnit test".
*
* The purpose of this is to show you how you can continue testing, just by taking the semi colon out, and continuing with your test.
*/
@Test
public void test() {
// click/validateAttribute
click(props.get("click"))
.validateAttribute(props.get("click"), "class", "success") // validate that the class indeed added.
// setText/validateText
.setText(By.id("setTextField"), "woot!")
.validateText(By.id("setTextField"), "woot!") // validates that it indeed set.
// check/uncheck
.check(By.id("checkbox"))
.validateChecked(By.id("checkbox")) // validate that it checked
.check(props.get("radio.2")) // remember that props come from <class name>.properties, and are always CSS selectors. (why use anything else, honestly.)
.validateUnchecked(props.get("radio.1")) // since radio 1 was selected by default, check the second one, then validate that the first radio is no longer checked.
// select from dropdowns.
.selectOptionByText(By.xpath("//select[@id='select']"), "Second") // just as a proof of concept that you can select on anything. But don't use xpath!!
.validateText(By.id("select"), "2") // validateText() will actually return the value="" attr of a dropdown, so that's why 2 works but "Second" will not.
.selectOptionByValue(By.cssSelector("select#select"), "3")
.validateText(props.get("select"), "3")
// frames
.switchToFrame("frame") // the id="frame"
.validatePresent(By.cssSelector("div#frame_content"))
// windows
.switchToWindow("Getting Started with Selenium") // switch back to the test window.
.click(By.linkText("Open a new tab/window"))
.waitForWindow("Google") // waits for the url. Can also be the you are expecting. :) (regex enabled too)
.setText(By.name("q"), "google!")
.closeWindow(); // we've closed google, and back on the getting started with selenium page.
}
}
您應該創建關於該對象的實例的webdriver和調用方法的實例。
一個簡單的示例如下所示:http://www.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example
我希望你已經創建了webdriver的腳本。
現在由硒IDE記錄的腳本,你有三種方法稱爲 設置,testSomeName和拆卸。
從最基本的角度來看:要運行這個腳本,你需要做的就是在同一個類中創建一個main方法,並且需要按照上面指定的順序調用這些方法。
之後,你只需要運行該程序。
下面是一個例子,使其更清楚:
public class p_adjcb {
public void setUp() throws Exception {
}
public void testP_adjcb() throws Exception {
}
public void tearDown() throws Exception {
}
public static void main(String[] args) {
p_adjcb obj = new p_adjcb();
try {
obj.setUp();
obj.testP_adjcb();
obj.tearDown();
} catch (Exception ex) {
}
}
}
如果你得到任何編譯錯誤,請確保你已經下載了selenium-standalone-server.jar
文件,並將其添加到您的類路徑。 這是一個非常基本的開始。稍後,您可能需要使用som框架,如junit。
希望它有幫助。
這是不好的..你爲什麼要把junit測試放在那裏,如果你甚至不使用junit ..你正在用Java處理這個任務,而不是像你應該這樣處理jUnit。 – sircapsalot
@sircapsalot:非常感謝。只是刪除了註釋。 –
啊是的,好多了:) – sircapsalot
桌面應用程序你在談論像IE瀏覽器,火狐或鉻瀏覽器? –
IDE允許您將其導出爲Java代碼。 – Arran