ユーザーがに新しいURLを入力したシミュレートしていますブラウザのURLバー、それは必要なページオブジェクトを作成するのはテストクラスの責任です。
一方、ブラウザが別のページを指し示すような操作をページ上で行っている場合(たとえば、リンクをクリックしたりフォームを送信した場合など)、そのページの責任があります次のページオブジェクトを返すオブジェクト。
私はそれはあなたのサイトに出てプレーしたい正確にどのようにあなたを伝えるためにあなたのホームページ、アカウントページ、および結果ページ間の関係について十分に知らないので、私は、一例として、オンラインストアのアプリを使用します代わりに。
検索ページがあるとします。 SearchPageでフォームを送信すると、ResultsPageが返されます。結果をクリックすると、ProductPageが表示されます。だから、クラスが(ちょうど関連するメソッドと略す)のようになります。
public class SearchPage {
public void open() {
return driver.get(url);
}
public ResultsPage search(String term) {
// Code to enter the term into the search box goes here
// Code to click the submit button goes here
return new ResultsPage();
}
}
public class ResultsPage {
public ProductPage openResult(int resultNumber) {
// Code to locate the relevant result link and click on it
return new ProductPage();
}
}
次のようなものになり、この物語を実行するための試験方法:だからあなたが見ることができるように
@Test
public void testSearch() {
// Here we want to simulate the user going to the search page
// as if opening a browser and entering the URL in the address bar.
// So we instantiate it here in the test code.
SearchPage searchPage = new SearchPage();
searchPage.open(); // calls driver.get() on the correct URL
// Now search for "video games"
ResultsPage videoGameResultsPage = searchPage.search("video games");
// Now open the first result
ProductPage firstProductPage = videoGameResultsPage.openResult(0);
// Some assertion would probably go here
}
を、それぞれが次のものを返すページオブジェクトのこの「連鎖」があります。
この結果、他のページオブジェクトをインスタンス化する多くの異なるページオブジェクトが生成されます。したがって、かなりのサイズのサイトがある場合は、それらのページオブジェクトを作成するための依存性注入フレームワークの使用を検討することができます。
"ページオブジェクト"とはどういう意味ですか? – Alp