SelendroidDriver not in jar file - java

I have recently written a Selenium program in Java that works perfectly with the FireFoxDriver(). My step 2 is to be able to run this program on my Android device with Selendroid. I went on their website here and have been able to download the jar and connect to their localhost with port:4444.
However, when I try their example, Eclipse doesn't recognize the SelendroidDriver() and suggests me to go back to WebDriver().
Here is their code:
SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.10.0");
// My error appears when I create the new SelendroidDriver().
WebDriver driver = new SelendroidDriver(capa);
WebElement inputField = driver.findElement(By.id("my_text_field"));
Assert.assertEquals("true", inputField.getAttribute("enabled"));
inputField.sendKeys("Selendroid");
Assert.assertEquals("Selendroid", inputField.getText());
driver.quit();
I have also noticed that the SelendroidDriver class does not appear in my files although I downloaded the Selendroid jar file, version 0.10.0.

For those of you who are curious about how I fixed my problem, here is what I did:
I went to this site to get the selendroid-client jar file corresponding to the standalone version I had.
Downloading the standalone jar file was somehow not enough.

I was facing the same problem till I found the SelendroidDriver class here. Import this and change the package name according to your project.
SelendroidDriver.java has classes implementing interface methods, which in Java 1.6 can be annotated with #Override. However, in Java 1.5, #override could only be applied to methods overriding a superclass method.
Go to your project preferences and set the "Java compiler level" to 1.6 and also make sure you select JRE 1.6 to execute your program from Eclipse.
After adding this class, you would still see multiple dependency errors, but now in the SelendroidDriver.java file. You can import these classes now to counter these errors. Ensure that the package hierarchies are maintained correctly, in accordance with the GitHub directories and your working project.
After importing all these classes, the constant fields SWITCH_TO_CONTEXT, GET_CONTEXT_HANDLES and GET_CURRENT_CONTEXT_HANDLE were not being resolved. I used a poor workaround of changing them to some other available constant field for testing this sample.

I struggled a lot with this error and finally came to know that the paths have been changed in the latest releases. Use these paths and it shall work:
import io.selendroid.common.SelendroidCapabilities;
import io.selendroid.client.SelendroidDriver;
Tested this for versions 0.15.0 & 0.17.0

Related

How do I resolve "the type is not accessible" error in Eclipse when using an external JAR? JAR in question is algs4 from Princeton [duplicate]

I'm new to the whole programming stuff but here's my problem:
I used to add my JUnit test cases in Eclipse by right clicking on the project, and just add New > JUnit Test Case.
Currently, I am not able to implement any test methods because Eclipse tells me on the line
import static org.junit.jupiter.api.Assertions.*;
the error message
The type org.junit.jupiter.api.Assertions is not accessible.
Error I get in the IDE:
I tried the following:
Reinstalling Eclipse, using a fresh workplace.
Adding the JUnit to Build path
Nothing helped.
It worked and works in older projects just fine.
Here is how the Package Explorer looks:
What am I missing?
You use the Java Platform Module System (JPMS) by having a module-info.java file in the default package probably without the required requires <module>; statement. JPMS was introduced in Java 9.
Do one of the following:
Delete the module-info.java file (if needed, you can recreate it via right-clicking the project folder and choosing Configure > Create module-info.java)
In module-info.java add the corresponding requires statement, e.g. by going to the line with the import statement and using the corresponding Quick Fix (Ctrl+1)

Eclipse throws the error "Data cannot be resolved to a type" for using the Project Lombok [duplicate]

This question already has an answer here:
Eclipse Java IDE JUnit5: junit.jupiter.api.Assertions is not accessible
(1 answer)
Closed 2 years ago.
I am new to Java and Project Lombok, I am trying to follow some tutorials to understand it better. I have created a very simple java project to test the Project Lombok and it throws the error Data cannot be resolved to a type when I add the annotation #Data to my class.
I am using macOS and Eclipse IDE for running my Java application. Following are the steps that I followed to run my first Java and Lombok project:
Downloaded the latest Project Lombok version 1.18.16 and placed it in the Documents folder.
Installed the Project Lombok in my system using the command java -jar lombok.jar.
Restarted my Eclipse and verified that Project Lombok installed in the Eclipse -> About Eclipse: "Lombok v1.18.16 "Envious Ferret" is installed. https://projectlombok.org/"
Created a new Java project and the class Alien.
Added the Project Lombok JAR to my project Classpath.
Added the #Data annotation to my Alien class and imported the JAR file but I get the error The type lombok.Data is not accessible for my import statement import lombok.Data;
Also, I get the error Data cannot be resolved to a type for my annotation at the class level public #Data class Alien
I am really unsure what's wrong. I tried to find out but all the answers have mentioned the same steps. I was just wondering what am doing wrong. Any help would be really appreciated.
Following is my complete code:
package com.lamboktest;
import lombok.Data;
public #Data class Alien {
private int age;
private String name;
}
The error The type SOMETYPE is not accessible is... bizarre. As far as I know, there are only three ways to get that error:
lombok.Data isn't public. Except, it is, so this can't be it.
You've manually added a list of forbidden packages ('access rules') in eclipse, to deny yourself access to lombok. Presumably, you'd remember if you did that, so it can't be this.
lombok is loaded as a module, and the lombok package isn't exported. Except, the only versions of lombok that exist either aren't modularized (and module-info-less jar files export everything), or they are, and the lombok package is exported. So it can't be this.
Perhaps it would be useful to doublecheck all of these:
I guess javap -cp lombok.jar lombok.Data, and check that it's public, but, this just cannot be it, so you probably don't need to bother.
For that access rules thing, which is the most likely of 3 very unlikely options, go into your project's setup (right click on it in e.g. the package explorer, and pick 'properties...', you can set up lots of stuff from there), go to 'build path', find the lombok.jar, open it up, and check 'access rules'. It should read 'no rules defined'.
Go into your project's setup and ensure it's all set to java8, and rebuild. Presumably you want to use new features, but the point is to at least isolate down to: It's a module issue.
Posting the answer as it maybe useful for somebody in the future.
As mentioned in the comment removed/deleted the file module-info.java which was created by default during the project creation. Everything worked as expected.

Why do i get a java.lang.NoSuchMethodError: even though the build is green?

I wrote a test using HtmlUnitDriver in intellij.
The code is:
import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class HtmlUnitDemo {
WebDriver driver;
public static void main(String args[]){
HtmlUnitDemo obj = new HtmlUnitDemo();
obj.setup();
obj.openURL();
}
public void openURL() {
driver.get("https://mail.google.com");
driver.findElement(By.id("username")).sendKeys("xyz");
driver.findElement(By.id("password")).sendKeys("pqr");
driver.findElement(By.className("btn-submit")).click();
Assert.assertEquals(driver.getTitle(), "CAS – Central Authentication Service");
}
public void setup(){
driver = new HtmlUnitDriver();
}
}
This code builds when i use gradle. But, when I run it in the IDE, it gives me a
*java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)
The entire stack trace is:
at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:504)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClient(HttpWebConnection.java:470)
at com.gargoylesoftware.htmlunit.HttpWebConnection.setUseInsecureSSL(HttpWebConnection.java:659)
at com.gargoylesoftware.htmlunit.WebClient.setUseInsecureSSL(WebClient.java:1085)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:263)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:129)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:172)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:168)
at smoke.com.thoughtworks.twu.HtmlUnitDemo.setup(HtmlUnitDemo.java:30)
at smoke.com.thoughtworks.twu.HtmlUnitDemo.main(HtmlUnitDemo.java:14)
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:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
I googled this error and it said something related to class path. But I am not sure what exactly is to be done. I am very new to this field. So any help will be deeply appreciated.
Thank you in advance.
NoSuchMethodError might indicate that the library where the class org.apache.http.conn.scheme.Scheme is has a different version that what is expected.
Check the dependencies used by the Selenium library you are using. If it's from maven it can be a simple task, otherwise check on their website.
I had this same error and was very difficult for me to solve.
java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)
There are two classes on my Classpath that have the same "fully qualified" name
org.apache.http.conn.scheme.Scheme
Java simply picks the first Scheme class is sees and it's the wrong one. It uses the Scheme class that doesn't have the method I expect.
Ok so I fix by just declaring the right dependency in Maven right? No. Both of the Scheme classes are in different Artifacts, and one is a transitive dependency so I can't remove completely.
Solution We had to manually override Maven by putting the Jar of the Scheme class we want to use inside Tomcat. The dependencies picked up by the Tomcat container are loaded before the Maven dependencies. So load the Scheme class Jar into your web container so you can guarantee it's found first.
These commands were very useful while analyzing.
mvn dependency:analyze -o
mvn dependency:tree -o
If you are using IntelJ IDE. Make sure you are giving right JDK in the project detail. You can check it by
Press Ctrl+Alt+Shift+S -> Will open Project Settings.
click on project. You can see which JDK you are specified there.
Go to your path of JDK in your system. If you are on Windows 64 bit version. it will be
C:\Program Files\Java\
Make sure The JDK you have specified also have the corresponding jre in the same path(JDK,JRE version should be same).
So you can see I have jdk1.8.0_141, jre1.8.0_141. And I have Indexed This jdk1.8.0_141 to my IntelJ.
When you are checking If you see like Corresponding JRE not present. IntelJ indexing will not be proper and it lead to such errors which you mentioned in the question.
You can download latest JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html
If you are on windows use .exe version of JDK and run in your system. Which will automatically install corresponsind jre in the same path.
You can put your doubts on comments. Will try to help you out.
After that come back to IntelJ. Go project Settings->projects. Click New and select and add the proper JDK. Click OK. Then Go to your program. you can see IntelJ Is reindexing your things. May take couple of minutes. After that try to re run the program.

Java class methods do not auto complete in Jython using Eclipse Pydev

I'm using PyDev 2.5 with Eclipse Indigo and Jython 2.5.3b1 . I have a JAR file that contains certain classes which I'm importing to a PyDev (Jython ) project. They seem to work seamlessly except for Auto completion. The member functions of Java Classes do not auto-complete e.g. pressing the dot '.' operator does not bring up the list for class member functions. The jar file is added to the PyDev-PYTHONPATH external libraries of the PyDev project.
Screenshot of PYTHONPATH external libs
Auto completion does not work for the code below, but it compiles and runs perfectly fine.
from my.testpackage import MyClass
myVar = MyClass("Monkey")
print myVar.getName()
Typing "myVar." does not auto complete
Worth noting that auto completion works if I imported a non custom jar
e.g.
from java.lang import Math
print Math.max(3,5)
Typing "Math." will auto complete
I'm not sure if this functionality even supported in the current version of PyDev. Does anyone actually have this working in their PyDev and Eclipse setup?
Any suggestion would be appreciated.
Thank you,
DM
It may be some issue in your PYTHONPATH configuration. Have you read: http://pydev.org/manual_101_project_conf2.html (most specifically the end of the page: "Project reference for Jython users").
If that doesn't help you, can you explain how are you referencing things? (a screenshot with the config would be nice)

Eclipse 3.5+ - Annotation processor: Generated classes cannot be imported

I am using a 3rd party annotation processor for generating meta-data code (.java files) from the annotated classes in my project.
I have successfully configured the processor through Eclipse (Properties -> Java Compiler -> Annotation Processing) and the code generation works fine (code is automatically created and generated). Also, Eclipse successfully auto-completes the generated classes and their fields, without any errors. Let's say that I have a class "some.package.Foo" and that the generated meta-data class is "some.package.Foo_". By the help of auto-completion, I can get the following code in the Eclipse editor, without any errors:
import some.package.Foo_;
...
public class Test {
void test() {
Foo_.someField = null; // try to access a field from the generated class Foo_
}
}
However, as soon as I actually build the project (or just save the file since Build automatically is enabled), I get the error which tells that "some.package.Foo_" cannot be resolved.
It seems like Eclipse is generating and compiling the some.package.Foo_ at the same time, or more likely.
I found two temporary solutions (which are practically hindering the use of the annotation processor in the first place):
Before each build of that generated classes, right click on every generated file go to Properties and uncheck the "Derived" tick. After that, I do the cleanup of the project and the imports are fine - there are no more errors. However, if I do the cleanup one more time, the errors again show up, because the generation of the files causes the "Derived" tick to be checked again (automatically). So this is really annoying and time-consuming.
I also uncheck the "Derived" tick
from all those files, and this time
I uncheck the "Derived" tick from
the source folder and packages which
contain those files. Then I disable
the annotation processor, and then
do the cleanup. There are no more
import errors, even if I do another
cleanup, but there is no benefit of
using the annotation processor,
because if I was to change something
which would update the model, I need
to turn the annotation processor
back on, and repeat this tedious
procedure to turn it off, after it
has generated the new version of
those files.
Is this a bug in Eclipse? If yes, is there a better workaround or quick-fix than the two I have stated above? If not, what should I try to solve the problem?
I also tried rearranging the order of the libraries on the build path and it doesn't help.
I assume that you are generating sources in the last processor round. This is not recommended way and leads exactly to the problem that you had.
Explanation is here: http://code.google.com/p/acris/wiki/CodeGenerationPlatform_Pitfall_Rounds
So the my advise is to generate sources in regular processing rounds and final round should be used just for notification that processing is over or something like that.
Hopefully this helps you.
I have a similar problem, and the only thing I've found is that it's the imports specifically that don't work, but the references in the class itself do work. The workaround I've used is to use the FQCN in all cases where the generated class is needed (except when the generated class is in the same package, since then the import is obviously not needed).
So to use your example, I'd do:
public class Test {
void test() {
some.package.Foo_.someField = null; // try to access a field from the generated class Foo_
}
}
My only guess then is that the eclipse compiler is processing the imports before doing the annotation processing, which imho must be a bug in eclipse.
I know this question is over a year old, so I'd be interested to know if you've found any other way to fix it.
We were experiencing a similar problem and apparently just solved it, so thought of sharing it at SO, in case it helps someone.
We are using:
Eclipse Indigo (Build id: 20120216-1857)
m2e Connector for maven
openJPA for static metamodel class generation
Our problem:
Say, we have a package named com.abc.xyz and an entity class in there named OurEntity. When we build the projects (JPA, EJB, EAR etc. all together with an mvn clean at the beginning) the metamodel classes get generated. And also get appropriately packaged within the PU jar. But when we try to import the generated metamodel class com.abc.xyz.OurEntity_, Eclipse cannot resolve it. OP apparently got past this point:-). Maven build failed, saying it could not resolve that class. Not much help from google except for a few bug reports such as this one: https://bugs.eclipse.org/bugs/show_bug.cgi?id=350378
That bug report said importing the whole package as opposed to the single class helped. So, tried that, but with no benefit. It also said (and so did David Heitzman) that using the fully qualified class name worked for them. That did not work either.
The solution:
Added the PU jar to Eclipse build path for the project that needed to use the metamodel classes. All of a sudden all the red underlines went away (not a surprise). But the fear was there might be two PUs in the same ear. But maven automagically took care of that.
As this rather old question got some attention without pointing to the very probable eclipse bug the OP was specifically asking for, I'd like to complement the above answers with a pointer to the eclipse bug tracker:
Cannot resolve import for generated class IF processing annotations with parameters referencing constants
The workarounds include
doing a wildcard import of the package defining the generated classes (i.e. import some.package.*;)
using the fully qualified name of your generated class, i.e. referring to some.package.Foo in your code and not using an import
switch to a newer Eclipse. This specific eclipse bug is resolved with Eclipse version 4.4 (aka Luna).

Categories