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

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.

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.

Junit test Failed not finding AssertArrayEquals Method in Assert class

I am using Junit 4.1. When I tried to use AssertArrayEquals(...) it's not finding that method. I tried importing everything by import static org.junit.Assert.*;. I searched in the jar file but I didn't find this method, and need suggestions to resolve this.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
public class ArraysCompareTest {
#Test
public void testArraySort() {
int [] actual= {8,7,6,5};
int [] expected= {5,6,7,8};
Arrays.sort(actual);
//it fails because it checks object references not content
assertArrayEquals(expected, actual);
}
}
The problem here is Assert class is not showing AssertArrayEquals in suggestion.
Are you sure you have the JUnit4 jar? Assert.AssertArrayEquals wasn't present in JUnit3 and before.

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

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.

Create PicasawebService

I try to get the titles and URLs from a public Picasa album. But I am stuck at the very beginning: I cannot create a new PicasawebService.
My Code:
import java.util.List;
import java.io.File;
import java.net.URL;
import com.google.gdata.client.*;
import com.google.gdata.client.photos.*;
import com.google.gdata.data.*;
import com.google.gdata.data.media.*;
import com.google.gdata.data.photos.*;
import java.util.ArrayList;
public class PicasaManager implements PicasaConnector {
public List<Avatar> getPhotoURLs() throws Exception {
PicasawebService myService = new PicasawebService("HI");
myService.setUserCredentials("foo#gmail.com", "mypassword");
ArrayList<Avatar> rl = new ArrayList<Avatar>();
URL feedUrl = new URL("https://picasaweb.google.com/111420671758947023853/EWA2012");
System.out.println("dddddddddddddddddd");
AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class);
for (PhotoEntry photo : feed.getPhotoEntries()) {
Avatar a1 = new Avatar();
a1.setDescription(photo.getTitle().getPlainText());
a1.setUrl(photo.getMediaThumbnails().get(0).getUrl());
rl.add(a1);
}
return (rl);
}
}
The Error Message:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
at com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
at com.google.gdata.client.Service.<clinit>(Service.java:558)
at tuwien.big.mensch.utilities.PicasaManager.getPhotoURLs(PicasaManager.java:27)
at tuwien.big.mensch.utilities.test.main(test.java:29)
test.java is my test class with the public static void main method,
Avatar is a class with two variables: description and url, there are getters and setters for both
in my netbeans IDE line 27 of the PicasaManager.java file is: PicasawebService myService = new PicasawebService("HI");
the implemented interace only defines the getPhotoURLs() method
I have no idea how to solve this problem, i hope somebody here can help me.
Have you included gdata-core-1.0.jar and guava-12.0.jar? Good luck on the rest of Web Engineering UE4 ;-)