Appium - PageFactory initElements is not working
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have this Class as my page object:
public class LaunchPageObject {
private AppiumDriver<AndroidElement> driver;
public LaunchPageObject() {
}
public LaunchPageObject(AppiumDriver<AndroidElement> driver) {
this.driver=driver;
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}
public void Click_SigninNow() {
lnk_SigninNow.click();
}
@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;
@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;
@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
}
and I have this class as my test case class:
public class LaunchPageTest extends Android {
@Test
public void Click_SigninNow() throws MalformedURLException {
LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}
I have this error log:
FAILED: Click_SigninNow
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at POM.LaunchPageObject.(LaunchPageObject.java:35)
at TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
The test opens the app but is not able to click the element. Any idea what is happening here?
appium appium-android
add a comment |
I have this Class as my page object:
public class LaunchPageObject {
private AppiumDriver<AndroidElement> driver;
public LaunchPageObject() {
}
public LaunchPageObject(AppiumDriver<AndroidElement> driver) {
this.driver=driver;
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}
public void Click_SigninNow() {
lnk_SigninNow.click();
}
@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;
@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;
@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
}
and I have this class as my test case class:
public class LaunchPageTest extends Android {
@Test
public void Click_SigninNow() throws MalformedURLException {
LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}
I have this error log:
FAILED: Click_SigninNow
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at POM.LaunchPageObject.(LaunchPageObject.java:35)
at TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
The test opens the app but is not able to click the element. Any idea what is happening here?
appium appium-android
Can you add setDriver() method too?
– Suban Dhyako
Nov 23 '18 at 9:01
I think setting your AppiumDriver as static will solve the problem.
– Suban Dhyako
Nov 23 '18 at 11:40
add a comment |
I have this Class as my page object:
public class LaunchPageObject {
private AppiumDriver<AndroidElement> driver;
public LaunchPageObject() {
}
public LaunchPageObject(AppiumDriver<AndroidElement> driver) {
this.driver=driver;
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}
public void Click_SigninNow() {
lnk_SigninNow.click();
}
@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;
@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;
@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
}
and I have this class as my test case class:
public class LaunchPageTest extends Android {
@Test
public void Click_SigninNow() throws MalformedURLException {
LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}
I have this error log:
FAILED: Click_SigninNow
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at POM.LaunchPageObject.(LaunchPageObject.java:35)
at TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
The test opens the app but is not able to click the element. Any idea what is happening here?
appium appium-android
I have this Class as my page object:
public class LaunchPageObject {
private AppiumDriver<AndroidElement> driver;
public LaunchPageObject() {
}
public LaunchPageObject(AppiumDriver<AndroidElement> driver) {
this.driver=driver;
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}
public void Click_SigninNow() {
lnk_SigninNow.click();
}
@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;
@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;
@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
}
and I have this class as my test case class:
public class LaunchPageTest extends Android {
@Test
public void Click_SigninNow() throws MalformedURLException {
LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}
I have this error log:
FAILED: Click_SigninNow
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at POM.LaunchPageObject.(LaunchPageObject.java:35)
at TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
The test opens the app but is not able to click the element. Any idea what is happening here?
appium appium-android
appium appium-android
edited Nov 26 '18 at 4:29
Wasiq Bhamla
709159
709159
asked Nov 22 '18 at 23:06
HamidHamid
13310
13310
Can you add setDriver() method too?
– Suban Dhyako
Nov 23 '18 at 9:01
I think setting your AppiumDriver as static will solve the problem.
– Suban Dhyako
Nov 23 '18 at 11:40
add a comment |
Can you add setDriver() method too?
– Suban Dhyako
Nov 23 '18 at 9:01
I think setting your AppiumDriver as static will solve the problem.
– Suban Dhyako
Nov 23 '18 at 11:40
Can you add setDriver() method too?
– Suban Dhyako
Nov 23 '18 at 9:01
Can you add setDriver() method too?
– Suban Dhyako
Nov 23 '18 at 9:01
I think setting your AppiumDriver as static will solve the problem.
– Suban Dhyako
Nov 23 '18 at 11:40
I think setting your AppiumDriver as static will solve the problem.
– Suban Dhyako
Nov 23 '18 at 11:40
add a comment |
1 Answer
1
active
oldest
votes
Keep your page object and test classes like below
public class LaunchPageObject {
@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;
@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;
@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
public void click_SigninNow() {
lnk_SigninNow.click();
}
}
public class LaunchPageTest extends Android {
LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);
@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}
}
Thank you! it worked :)
– Hamid
Nov 23 '18 at 14:38
Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?
– Bill Hileman
Dec 4 '18 at 16:34
Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..
– Balakrishnan A
Dec 25 '18 at 5:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438918%2fappium-pagefactory-initelements-is-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Keep your page object and test classes like below
public class LaunchPageObject {
@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;
@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;
@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
public void click_SigninNow() {
lnk_SigninNow.click();
}
}
public class LaunchPageTest extends Android {
LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);
@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}
}
Thank you! it worked :)
– Hamid
Nov 23 '18 at 14:38
Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?
– Bill Hileman
Dec 4 '18 at 16:34
Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..
– Balakrishnan A
Dec 25 '18 at 5:00
add a comment |
Keep your page object and test classes like below
public class LaunchPageObject {
@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;
@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;
@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
public void click_SigninNow() {
lnk_SigninNow.click();
}
}
public class LaunchPageTest extends Android {
LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);
@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}
}
Thank you! it worked :)
– Hamid
Nov 23 '18 at 14:38
Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?
– Bill Hileman
Dec 4 '18 at 16:34
Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..
– Balakrishnan A
Dec 25 '18 at 5:00
add a comment |
Keep your page object and test classes like below
public class LaunchPageObject {
@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;
@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;
@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
public void click_SigninNow() {
lnk_SigninNow.click();
}
}
public class LaunchPageTest extends Android {
LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);
@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}
}
Keep your page object and test classes like below
public class LaunchPageObject {
@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;
@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;
@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
public void click_SigninNow() {
lnk_SigninNow.click();
}
}
public class LaunchPageTest extends Android {
LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);
@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}
}
answered Nov 23 '18 at 10:06
Balakrishnan ABalakrishnan A
1415
1415
Thank you! it worked :)
– Hamid
Nov 23 '18 at 14:38
Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?
– Bill Hileman
Dec 4 '18 at 16:34
Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..
– Balakrishnan A
Dec 25 '18 at 5:00
add a comment |
Thank you! it worked :)
– Hamid
Nov 23 '18 at 14:38
Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?
– Bill Hileman
Dec 4 '18 at 16:34
Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..
– Balakrishnan A
Dec 25 '18 at 5:00
Thank you! it worked :)
– Hamid
Nov 23 '18 at 14:38
Thank you! it worked :)
– Hamid
Nov 23 '18 at 14:38
Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?
– Bill Hileman
Dec 4 '18 at 16:34
Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?
– Bill Hileman
Dec 4 '18 at 16:34
Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..
– Balakrishnan A
Dec 25 '18 at 5:00
Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..
– Balakrishnan A
Dec 25 '18 at 5:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438918%2fappium-pagefactory-initelements-is-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you add setDriver() method too?
– Suban Dhyako
Nov 23 '18 at 9:01
I think setting your AppiumDriver as static will solve the problem.
– Suban Dhyako
Nov 23 '18 at 11:40