デスクトップ アプリケーションを介して Web ページをテストする必要があります。Selenium IDE を使用しようとしています。テスト ケースの作成には成功しましたが、Java で実行できません。
何か役立つものを探していましたが、まったく助けが見つかりません。
ありがとうございました
webdriver でスクリプトを作成したことを願っています。
Selenium ide によって記録されたスクリプトには、 setup、testSomeName、tearDownという 3 つのメソッドがあります。
非常に基本的なことから: このスクリプトを実行するには、同じクラスにメイン メソッドを作成し、これらのメソッドを上記と同じ順序で呼び出す必要があります。
その後、そのプログラムを実行するだけです。
より明確にするための例を次に示します。
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
ファイルをダウンロードしてクラス パスに追加したことを確認してください。これは非常に基本的なスタートです。後でjunitのような som フレームワークを使用する必要があるかもしれません。
それが役に立てば幸い。
この目的のために作成されたフレームワーク (Java で作成されています) は、ここからダウンロードするか、github からプロジェクトをチェックアウトできます。
このプロジェクトは、非常にシンプルでありながら非常に効果的なものになるように設計されました。このタイプのフレームワークは、プロダクション タイプの環境で毎日使用するフレームワークの私の解釈の「無料バージョン」です。
という名前のプロジェクトに含まれているサンプル テストがありSampleFunctionalTest.java
ます。ReadMe を 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.
}
}