Have problem with my automation selenium code on launching simple chrome browser - selenium

I am just starting my automation testing but landed with some error tired with debugging can someone please help here i have java libraries & selenium server standalone.
Error/
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for
D:\browser\selenium-server-standalone-3.141.59.jar Caused by:
java.lang.module.InvalidModuleDescriptorException: Provider class
org.eclipse.jetty.http.Http1FieldPreEncoder not in module

You need to use following
Webdriver driver = new ChromeDriver();
instead of
Webdriver driver = new ChromeDriverInfo();
Hope this will resolve your problem.

You haven't created a package.
-Inside the Java project: Create a new package
-Inside that package: Create a new Java class
-Copy and Paste this code into that file.
use this code :
Webdriver driver = new ChromeDriver();

Related

ClassNotFoundException using Selenium Standalone Server

I have a grails/groovy project that has one feature that uses selenium standalone server to do some test automation.
I keep getting this error running my grails project in production mode. If I run it directly from IntelliJ it works perfectly so I'm not sure what exactly is wrong.
Here is the relevant code:
WebDriver driver
DesiredCapabilities capability = DesiredCapabilities.chrome()
capability.setBrowserName("chrome")
capability.setPlatform(Platform.WINDOWS)
driver = new RemoteWebDriver( new URL("http://192.168.83.124:4444/wd/hub"), capability);
I'm getting a ClassNotFoundException error on the last line.
In my libraries for the project I'm using selenium-java-2.53.0.jar, selenium-server-standalone-2.53.0.jar and sources has selenium-java-2.53.0-srcs.jar
I have absolutely no idea what's wrong and I've searched the internet exhaustively to find a solution but have found nothing. Any help is appreciated.
Here is the full text of the error:
2017-12-08 15:59:56,381 [http-bio-8080-exec-1] ERROR
errors.GrailsExceptionResolver - ClassNotFoundException occurred when processing request: [GET] /Diversotron-0.1/api/edit
com.google.common.base.Function. Stacktrace follows:
java.lang.ClassNotFoundException: com.google.common.base.Function
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585)
at java.lang.Class.getDeclaredConstructors(Class.java:1906)
at
org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at diversotron.PropotronService.setPropotron(PropotronService.groovy:25)
at diversotron.ApiController.edit(ApiController.groovy:53)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
It's because Selenium isn't declared in my BuildConfig.groovy file. That's why it ran via IntelliJ but not in production. Doing a grails prod war will not include the libraries. They have to be specified in the buildconfoig.groovy file.
I had to add these lines.
def seleniumVersion = "2.53.0"
and in dependencies I had to add this:
runtime "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
Hopefully this will help someone else down the line!
Map chrome Options = new Map();
ChromeOptions.put("binary","/use/lib/chromium-browser/chromium-browser");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
Web Driver driver = new Chrome Driver(capabilities);
try this

Selenium - Java : PhantomJS : Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.HttpVerb

I am trying to instantiate a PhantomJS Driver with Selenium Java. Below is the code :
File file = new File("C:\\Softwares\\drivers\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
WebDriver driver = new PhantomJSDriver();
driver.get("http://www.google.com");
I have tried with different versions of Selenium and I am getting the same exception :
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.HttpVerb
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/HttpVerb
at org.openqa.selenium.phantomjs.PhantomJSDriver.getCustomCommands(PhantomJSDriver.java:166)
at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.<init>(PhantomJSCommandExecutor.java:62)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:110)
I'm using the below list of dependencies in my project :
phantomjsdriver
selenium-common.jar
selenium-java 2.53.1 . jar
The reason I'm using an outdated version of selenium library is due to some article I found over the internet saying that remote/HttpVerb is deprecated and downgrading the library would remove the error. However, I'm still getting this error
Please check this dependancy in POM
<dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-remote-driver</artifactId>
      <version>2.53.1</version>
    </dependency>
Check whether this class is present or not

Exception by using SafariDriver

I'm trying to run selenium safari driver.
My code is: driver = new SafariDriver();
But I get the following exception:
Caused by: java.lang.NoClassDefFoundError: org/jboss/netty/channel/ChannelFactory
at org.openqa.selenium.safari.SafariDriverCommandExecutor.<init>(SafariDriverCommandExecutor.java:76)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:58)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:42)
at com.ca.automation.utils.WebDriverFactory.initWebDriver(WebDriverFactory.java:168)
at com.ca.automation.utils.WebDriverFactory.getWebDriver(WebDriverFactory.java:210)
at com.ca.automation.utils.BaseSelenium.<init>(BaseSelenium.java:43)
at com.ca.automation.pb.strategicPlanning.CrudDriversBTest.<init>(CrudDriversBTest.java:20)
There could be a solution: Selenium 2 WebDriver NoClassDefFoundErrorS. You just need to use the standalone version or add all the jars to the build path.

illegalAccessError while using chromedriver with selenium

I am getting IllegalAccessError while using chromedriver in selenium. I have added chromedriver.exe to my path, and also set it in java code. here is my code
System.setProperty("webdriver.chrome.driver","C:/Users/me/Documents/chromedriver/chromedriver.exe");
WebDriver driver = new ChromeDriver();
here is the console output:
Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.openqa.selenium.remote.service.DriverService.checkExecutable(Ljava/io/File;)V from class org.openqa.selenium.chrome.ChromeDriverService
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:39)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.usingDriverExecutable(ChromeDriverService.java:104)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:72)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
I have also tried running the chromedriver.exe and then executing the code, still getting the error.
This is probably caused by using an older version of selenium, where the checkExecutable method was still private

NullPointer Exception In running testCases via Selenium webDriver in Chrome

I am trying to run my test cases on Chrome and I had copied the path in the Properties file,but still console is throwing annoying statements like:
ERROR: The path to the chromedriver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromium/downloads/list
FAILED CONFIGURATION: #BeforeTest startWebSession
java.lang.NullPointerException
One thing I have found is that the Chrome driver cannot be started from within Eclipse. It must be run from a command prompt. At least on Windows 7 64-bit.
Trying to run it from within Eclipse produces this exception:
Exception in thread "main" java.lang.IllegalStateException: The webdriver.chrome.driver system property defined chromedriver executable does not exist: C:\Windows\System32\chromedriver.exe
This problem only occurs for Chrome. IE and FireFox work fine from within Eclipse.
Download the chrome driver from http://code.google.com/p/chromedriver/downloads/list
Initialize your driver object in the following manner -
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
By doing this the chrome driver works properly.
This is how do I initialize the ChromeDriver:
public RegulationUI() throws Exception{
ChromeDriverService service = ChromeDriverService.createDefaultService();
File file = new File(RegulationUI.class.getResource("/chromedriver.exe").toURI());
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(service,options);
}
BTW my test class is named RegulationUI
Try this, it works for me and moreover, I know that this is "multicomputer" solution - our project is in subversion and this way everybody can run it, even if we have differently setup where exactly on disk the "working folder" for IDE is
Please download chromedriver.exe for Google chrome browser
please download IEdriver.exe for Internet explore.
Please And kept these files in a root folder of windows for simplicity. Lets consider your operating systems installed on c:\ (C Driver) create a folder name Selenium on C-Drive and Kept these binary(.exe) files. like c:\selenium
in your Testcase/testScript Write as
//For Chrome Browser:
Webdriver driver = new ChromeDriver();
java.io.File file = new File("c:\\selenium\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
If you are using maven then try to use following in your pom:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>RELEASE</version>
</dependency>
and use it like this for chrome in your setup:
ChromeDriverManager.getInstance().setup();
driver = new ChromeDriver();