我正在尝试使用Selenium创建一个测试用例,我将在一个名为“Policy”的页面中创建一个应用程序。 在这个应用程序中,我想创建一些成员。 要从Policy页面转到Members页面,必须在成功创建策略应用程序后按下“Members”按钮。 在创建您需要的所有成员后,您必须返回策略页面继续。 (主菜单页面 - >策略页面 - >成员页面 - >策略页面)
我正在使用页面对象模式。 我成功登录应用程序,导航到策略页面,创建应用程序,但无法转到成员页面以继续我的测试。 当然,返回到Policy页面。 我怎样才能做到这一点? 在Eclipse Console中显示消息“策略创建成功”后,我的测试失败。
我的代码是:
@Test public void TEST1_NavigateToPolicy() throws Exception { MenuPage.policySelection(); } @Test public void TEST2_PolicyCreation() throws Exception { PolicyPage.handleMultipleWindows("Policy"); PolicyPage.createPolicy( some requirements here); PolicyPage.checkMessageByIdContains("Operation Apply executed Successfully", MESSAGE); System.out.println("Policy Created succesfully"); } @Test public void TEST3_MemberCreation() { //Navigate to Member Page and Create Member PolicyPage.clickButton(MEMBERS_BUTTON); }I am trying to create a Test Case with Selenium, where I will create an application in one Page named "Policy". In this Application I want to create some Members. To go from Policy page to Members Page you have to press the button "Members" after you've successfully created the Policy Application. After creating all the members you need you have to navigate back to Policy page to continue. (Main Menu Page -> Policy Page -> Members Page -> Policy Page)
I am using Page Object Pattern. I successfully log in the App, navigate to Policy Page, create the Application, but cannot go to Members Page in order to continue my Test. And of course, get back to Policy page. How can I do that? My test fails after message "Policy Created succesfully" is shown in Eclipse Console.
My code is:
@Test public void TEST1_NavigateToPolicy() throws Exception { MenuPage.policySelection(); } @Test public void TEST2_PolicyCreation() throws Exception { PolicyPage.handleMultipleWindows("Policy"); PolicyPage.createPolicy( some requirements here); PolicyPage.checkMessageByIdContains("Operation Apply executed Successfully", MESSAGE); System.out.println("Policy Created succesfully"); } @Test public void TEST3_MemberCreation() { //Navigate to Member Page and Create Member PolicyPage.clickButton(MEMBERS_BUTTON); }最满意答案
那么这将是我的示例代码。
@Test public void TEST3_MemberCreation() { homePage = login(admin); PolicyPage policyPage = homePage.NavigateToPolicyPage(); policyPage.handleMultipleWindows("Policy"); policyPage.createPolicy( some requirements here); policyPage.checkMessageByIdContains("Operation Apply executed Successfully", MESSAGE); System.out.println("Policy Created succesfully"); } MembersPage membersPage = policyPage.clickMembersButton;(You have to handle the page navigation code inside this method and return MembersPage object) membersPage.createMember(Data); } MembersPage clickMembersButton(){ element.click(); switchTo.window(newWindowHandle); return new MembersPage(); }Then this will be my sample code for you.
@Test public void TEST3_MemberCreation() { homePage = login(admin); PolicyPage policyPage = homePage.NavigateToPolicyPage(); policyPage.handleMultipleWindows("Policy"); policyPage.createPolicy( some requirements here); policyPage.checkMessageByIdContains("Operation Apply executed Successfully", MESSAGE); System.out.println("Policy Created succesfully"); } MembersPage membersPage = policyPage.clickMembersButton;(You have to handle the page navigation code inside this method and return MembersPage object) membersPage.createMember(Data); } MembersPage clickMembersButton(){ element.click(); switchTo.window(newWindowHandle); return new MembersPage(); }更多推荐
发布评论