How to resolve androiddriver error messages?(Trying to setup automation mobile app testing using selenium eclipse oxygen and appium) - eclipse

I am getting the following error:
package amazon;
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class StartApplicationn {
private static AndroidDriver(OVER HERE) driver=null;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/Apps/Amazon/");
File app = new File(appDir, "in.amazon.mShop.android.shopping.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Galaxy Note5");
capabilities.setCapability("udid", "0915f95176431c05");
capabilities.setCapability("platformVersion", "7.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "in.amazon.mShop.android.shopping");
capabilities.setCapability("appActivity", "com.amazon.mShop.home.HomeActivity");
driver = new AndroidDriver(AND HERE)(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
driver.quit();
}
}
Both Androiddriver are underlined with a yellow line and I cant find a solution to it.
When I run appium it says no device found although I have checked all ways and it is attached. Sometimes when I connect my phone with PDA + it says adb.exe file is running so cant connect so when I shut it down it says no device found. but list is showing in the device manager for the phone to be connected.
Mainly Why is androiddriver underlined in eclipse? I believe that is where the problem lies.
Any suggestions on what might be the problem. As I have tried alot of things but it didn't work. Any help will be appreciated.

Instead of references to
AndroidDriver
Use:
AndroidDriver<AndroidElement>
The rest of your code, at a glance, looks okay.

Related

How to resolve “DesiredCapabilities cannot be resolved to a type"?

I am trying to run my first project with Appium on Eclipse and getting this error,
Exception in thread "main" java.lang.Error: Unresolved compilation
problems: DesiredCapabilities cannot be resolved to a type
DesiredCapabilities cannot be resolved to a type
at base.main(base.java:17)
Error: Unable to initialize main class base Caused by:
java.lang.NoClassDefFoundError:
io/appium/java_client/android/AndroidDriver
package Auto;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
public class base2 {
public static AndroidDriver<AndroidElement> dc() throws MalformedURLException
{
// TODO Auto-generated method stub
AndroidDriver<AndroidElement> driver;
File f = new File("src");
File fs = new File(f, "ApiDemos-debug.apk");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "DSEmulator");
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
dc.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), dc);
return driver;
}
}
Can someone point me what I must add to resolve this error?
I tried running the same code on my machine and it worked perfectly fine. This means that the problem is not with your code. Unresolved compilation problems generally occur whenever there is some problem with the jars referenced by your project. I would suggest you to remove all existing jars from the project build path, and then add them back carefully ensuring that you have all the required jars and then try re-runnning your code.

Eclipse JUnit 5 SecruityException when running Tests

I think I may be the only one experiencing this issue.
I, today, updated my eclipse install to version 2020-03 (4.15.0). I am also attempting to write a very simple JUnit 5 test for a new method I'm working on.
When I run my test, right now just a basic stub, I get the following error:
java.lang.SecurityException: class "org.junit.platform.commons.PreconditionViolationException"'s signer information does not match signer information of other classes in the same package
at java.base/java.lang.ClassLoader.checkCerts(ClassLoader.java:1150)
at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:905)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1014)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createUnfilteredTest(JUnit5TestLoader.java:75)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:66)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:53)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
I also see the following dialog
My run Configuration is:
I've tried all major junit-jupiter (aggregator) releases back to 5.5.0 all resulting in the same issue.
I've tried this solution. However, that question deals with a class not found issue. I also tried that same solution using using junit-platform-commons version 1.6.1. no change.
However, I can run maven configuration with -Dtest=DeaFileListTest test the the tests run.
My test case is simple, I instantiate an object that has the method I want to test and then my test.
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import java.io.IOException;
import java.util.List;
import javax.ws.rs.core.Response;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import com.mfgweb.FileRepo;
class DeaFileListTest {
private static FileRepo filerepo;
private static Response response;
#BeforeAll
static void setUpBeforeClass() throws Exception {
filerepo = new FileRepo();
response = filerepo.getDeaFiles();
}
#AfterAll
static void tearDownAfterClass() throws Exception {
response = null;
filerepo = null;
}
#Test
public void deaFileListIsNotEmptyTest() throws IOException {
#SuppressWarnings ( "unchecked" )
List< String > files = ( List< String > )response.getEntity();
assertThat( files, not( empty() ) );
}
}
So I am curious why I'm receiving the Security Exception when I run the test in eclipse, yet Maven seems to execute them fine.

Error: Could not instantiate class org.openqa.selenium.chrome.ChromeDriver

This error comes out when running the test.
I do not know how to solve it. they do not run in browser
Could not instantiate new WebDriver instance of type class
org.openqa.selenium.chrome.ChromeDriver
The code itself:
package com.automation.correo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import net.serenitybdd.junit.runners.SerenityRunner;
import net.thucydides.core.annotations.Managed;
import net.thucydides.core.annotations.Steps;
import pasos.pasoscorreo;
#RunWith(SerenityRunner.class)
public class testcorreo {
#Managed(driver = "chrome", uniqueSession = true)
WebDriver driver;
#Steps
pasoscorreo buyer;
#Test
public void Ingresar_Gmail_Valida_Correo_NoLeido() throws InterruptedException {
buyer.Abrir_Gmail();
buyer.Ingresar_usairio("Ingsisacontreras");
buyer.Ingresar_password("fdfdfd;");
buyer.Buscar_correo("Alejandro Rendon ");
buyer.UsuarioCon_correo();
buyer.Ultimo_correo();
buyer.Descripcion_Correo();
driver.close();
}
I had same issue during the first run of serenity-cucumber4-smoketests. The problem was in the chromedriver.exe version located in the skeleton. After I replaced it to a new one supported by my company, the test had passed. But same issue might happen if the path to the driver is not selected correctly.

Getting started with Stanford CoreNLP

I'm working in Java with the NetBeans IDE. I've downloaded the Stanford CoreNLP from their website and have no idea how to 'get it to work' in my Java project. I would like to be able to get this demo code working:
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.process.CoreLabelTokenFactory;
import edu.stanford.nlp.process.DocumentPreprocessor;
import edu.stanford.nlp.process.PTBTokenizer;
public class TokenizerDemo {
public static void main(String[] args) throws IOException {
for (String arg : args) {
// option #1: By sentence.
DocumentPreprocessor dp = new DocumentPreprocessor(arg);
for (List sentence : dp) {
System.out.println(sentence);
}
// option #2: By token
PTBTokenizer ptbt = new PTBTokenizer(new FileReader(arg),
new CoreLabelTokenFactory(), "");
for (CoreLabel label; ptbt.hasNext(); ) {
label = ptbt.next();
System.out.println(label);
}
}
}
}
But I have no idea how to achieve this. Off the bat, my import statements produce errors (can't find ___ package) Can someone provide step by step instructions for how to get this code to work?
When you downloaded Stanford CoreNLP it came with a file stanford-corenlp-<VERSION>.jar and a stanford-corenlp-<VERSION>-models.jar that you should put on the classpath.
This answer tells you how to do that with NetBeans: How to setup classpath in Netbeans?

IE browser opens even after specifying firefox using selenium testng

I am using Eclipse IDE and using testNG framework.
I have specified firefox but the test runner opens in Firefox and test gets executed in IE.
Here is my code:
public class Flipkart extends SeleneseTestNgHelper {
#BeforeTest
public void setup()
{
selenium = new DefaultSelenium("localhost" ,4444, "*firefox", "http://www.flipkart.com");
selenium.start();
selenium.windowMaximize();
}
#Test
public void testFlipkart() throws Exception {
selenium.open("http://www.flipkart.com");
verifyEquals(selenium.getTitle(), "Online Shopping India | Buy Books, Mobiles, Cameras, Laptops, Electronics, Accessories, Lifestyle Products | Flipkart.com");
verifyTrue(selenium.isTextPresent("Featured:"));
}
}
Has anyone faced the same problem. Please suggest what's wrong with code.
change the eclipse default browser to firefox(sometimes it helps)
add firefox to class path. also take a look at the firefox version you are using this should be compatible with selenium
Use *chrome instead of *firefox.
Also, check if the selenium server started.
You can try these steps ::
*STEP 1* : import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
*Step 2* : WebDriver driver = new FirefoxDriver();
*Step 3* : driver.get("http://www.google.com");
I was also getting same problem, Try out below code for Solution this will help you
public static String browser="firefox"; //declare Browser this in the class heading.
#BeforeSuite
public void setupBeforeSuite() throws Exception{
selenium = new DefaultSelenium("localhost", 4444,browser, "http://www.google.com");
selenium.start();
}