初始化页面对象-Arquillian-Selenium [英] Initialize Page Objects - Arquillian - Selenium
问题描述
我是Selenium和Arquillian框架的新手.我正在尝试实现页面对象模型. Webdriver浏览器功能保存在Arquillian xml文件中.
I am new to Selenium and Arquillian framework. I am trying to implement Page Object Model. Webdriver browser capabilities are saved in arquillian xml file.
我正在使用TestNG并创建了以下类:
I am using TestNG and created the following classes:
public class Test{
@Drone
Webdriver driver;
@Page
Login login;
@Page
Home home;
public void createOrderTest(){
login.navigateURL();
login.setcredentials();
home.createOrder();
}
}
public class Login{
// Webelements needed in methods below are declared here
public void navigateURL(){
driver.get("//url/login.aspx");
}
public void setCredentials(){
// code to enter username, password and click login
Graphene.waitAjax().until().element(signIn).is().not().visible();
}
}
public class Home{
// Webelements needed in methods below are declared here
public void createOrder(){
// code to create order
}
}
问题陈述:
我不确定如何在代码中的Login
和Home
页面之间导航.用户使用Login
页面方法登录后,Webdriver如何使用Home
页面方法继续测试?
Problem Statement:
I am not sure how to navigate between Login
and Home
pages in code. Once user logs in using Login
page methods, how does Webdriver get to use Home
page methods to continue the test ?
错误:
使用navigateURL
和setcredentials
方法可以正常运行.但是,测试无法访问createOrder
方法,如下所示:
Test runs fine with navigateURL
and setcredentials
methods. However, test fails to access createOrder
method as follows:
WARNING: Argument 1 for UpdateTestResultBeforeAfter.update is null. It won't be invoked.
FAILED CONFIGURATION: @BeforeMethod arquillianBeforeTest(public void Test.createOrder() throws javax.mail.MessagingException,java.io.IOException,java.security.GeneralSecurityException)
org.jboss.arquillian.graphene.enricher.exception.PageObjectInitializationException: Can not instantiate Page Object class Home
请指导我.谢谢.
推荐答案
主页是静态页面吗?我认为您不应该将登录页面重定向到主页.这应该由应用程序本身完成.也就是说,最终用户将使用url访问登录页面.所有的导航应该由应用程序本身完成.
Is the home page a static page? I assume you should not redirect the login page to home page. This should be done by the application itself. That is, end user will access the login page with url. after the all the navigations should be done by the application itself.
@RunAsClient
public class Test extends Arquillian{
@Drone
Webdriver driver;
@Page
Login login;
@Page
Home home;
public void createOrderTest(){
login.navigateURL();
login.setcredentials();
//you do not need this
//home = Graphene.goTo(Home.class)
//use graphene fluent wait API to wait for the page load
home.createOrder();
}
}
这篇关于初始化页面对象-Arquillian-Selenium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!