Page factory not working in appium 1.2.3

appium - 1.2.3
android version - 4.4.2
java client - 2.0.0
OS - Windows 7

public class Napp

{

@AndroidFindBy(name = “Data usage”)

private WebElement setdata;

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(“appPackage”, “com.android.settings”);
capabilities.setCapability(“appActivity”, “.Settings”);

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “4.4.2”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “Nexus 5”);

driver = new AndroidDriver(new URL(“http://0.0.0.0:4723/wd/hub”), capabilities);

PageFactory.initElements(new AppiumFieldDecorator(driver),this);

setdata.click();

Following is the error

java.lang.NoClassDefFoundError: org/reflections/Reflections
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.(AppiumFieldDecorator.java:42)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.(AppiumFieldDecorator.java:34)
at Napp.setUp(Napp.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.reflections.Reflections
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 27 more

It looks strange…
I have added this

       <groupId>org.reflections</groupId>
       <artifactId>reflections</artifactId>
       <version>0.9.8</version>

with exclusions

			        <artifactId>guava</artifactId>
				<groupId>com.google.guava</groupId>

and

				<artifactId>xml-apis</artifactId>
				<groupId>xml-apis</groupId>

in order to simplify further work if there will be, for example, FireFoxOSElement, WinMobileElements. MobileElement is extended by AndroidElement and IOSElement now.

Right now I am running my tests with java-client 2.0 and there is OK.
Please check out pom.xml. Is it possible that it is excluded in your project?

Please check the presence of this jar:

@SergeyTichomirov and @sendlink , Even i tried with AndroidDriver. Its works fine with me…

@SergeyTichomirov
i’ve included reflections-0.9.8 jar as specified, after running the code i got new error

com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
at com.google.common.cache.LocalCache.get(LocalCache.java:3932)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806)
at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:113)
at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:26)
at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:27)
at org.reflections.Reflections.scan(Reflections.java:217)
at org.reflections.Reflections.scan(Reflections.java:166)
at org.reflections.Reflections.(Reflections.java:94)
at org.reflections.Reflections.(Reflections.java:135)
at org.reflections.Reflections.(Reflections.java:108)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.(AppiumFieldDecorator.java:42)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.(AppiumFieldDecorator.java:34)
at Napp.setUp(Napp.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
at org.reflections.adapters.JavassistAdapter.createClassObject(JavassistAdapter.java:126)
at org.reflections.adapters.JavassistAdapter$1.load(JavassistAdapter.java:38)
at org.reflections.adapters.JavassistAdapter$1.load(JavassistAdapter.java:37)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3522)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2315)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2278)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2193)
… 38 more
Caused by: java.lang.ClassNotFoundException: javassist.bytecode.ClassFile
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 45 more

Hmm… Looks like conflict of libraries. Please show your pom.xml fragment where dependencies are declared.

What Selenium version are you use? Appium java client depends on 2.43.1.

Hi Sergey i am using appium 1.2.0

using @AndroidFindBy getting the same error of reflections can you please check

added jars - javaclient -2.0.0
selenium java - 2.43.1
selenium server standalone 2.43.1

Earlier i was not using @AndroidFindBy And it was working fine.

Also i have created a java project with TestNG and not a maven project and i am getting the same error of reflections .

FAILED CONFIGURATION: @BeforeMethod setup
java.lang.NoClassDefFoundError: org/reflections/Reflections
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.(AppiumFieldDecorator.java:42)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.(AppiumFieldDecorator.java:34)
at test.BaseTestClass.setup(BaseTestClass.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ClassNotFoundException: org.reflections.Reflections
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
… 29 more

@sendlink i am getting the same error after adding the reflections0.98 jar

Can you tell me how did you resolve this ?

@sendlink & @SergeyTichomirov - I imported reflections & javassist jars and it worked perfectly.

Replying for others who face the same issue!

Thanks for info! I am going to work out this problem. It is weird :frowning: Mayby it needs a dependency.
Did you add javassist as a maven dependency?

@SergeyTichomirov, even i did not face this. need to find out actual root cause.

I think so. I have never faced up this. I think there are conflicts of libraries.

@sanjit1walia could you show your pom.xml fragment or some screenshot? I need to see dependencies

Also i have created a java project with TestNG and not a maven project and i am getting the same error of reflections .

or imported library list

Hi ,Yes i have added javassist -3.12.1.GA.jar as a maven dependency and it is also present when i see the java client 2.0.0 project .

@Priyank_Shah @SergeyTichomirov - this happens only when you make a JAVA project and then work .

I have created a Maven project and put all the dependencies in pom.xml and it worked fine for both Android & iOS.

However, if you make a java project ,for Android you need to import - javassist & reflections.jar

For iOS i have imported these 2 jars but still getting NullPointer exception - working on to figure out what is wrong there ( the same code works perfectly in my maven project) .

Please share information about the second problem working out!

I haven’t work with simple java projects much time…

I am going to propose a new pull request. There will be AndroidFindAll and iOSFindAll. I found a situation when there is needed something similar as @FindAll in Selenium. Maybe there will be fix of this problem…

I cleaned my code and re-run it ,and alas it worked
Now for both iOS & Android i had to import reflections & javassist for simple java project.

And for maven project i had added them in my pom.xml

Issue: https://github.com/appium/java-client/issues/120

1 Like

Fixed: https://github.com/appium/java-client/pull/125.

Please wait for new available version.