Running Selenium-java automation inside Gitpod - testing

New to the platform & test automation & selenium. I got introduced to Gitpod while attempting https://www.lambdatest.com/certifications/.
for starters I'm stuck trying to run the below simple code snippet in side Gitpod
package project.maven.selenium;
import org.openqa.selenium.WebDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class WebDriverManagerDemo {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = WebDriverManager.chromedriver().create();
// Navigate to the demoqa website
driver.get("https://www.lambdatest.com/selenium-playground/checkbox-demo");
Thread.sleep(3000);
driver.quit();
}
}
Couldn't find a way pass the error below,
Exception in thread "main" io.github.bonigarcia.wdm.config.WebDriverManagerException: There was an error creating WebDriver object for Chrome
at io.github.bonigarcia.wdm.WebDriverManager.instantiateDriver(WebDriverManager.java:1775)
at io.github.bonigarcia.wdm.WebDriverManager.create(WebDriverManager.java:425)
at project.maven.selenium.WebDriverManagerDemo.main(WebDriverManagerDemo.java:9)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
can someone point out what I'm doing wrong please?
Researched hours but Selenium on Gitpod is not much of a topic, read the getting started guide with Gitpod too, to find a resolution to my problem but no luck before posting here.

Related

ChromeDriver Selenium exception

Im using Mac laptop, I got this from youtube for mac tutorial, but its working for other students
Forgive me I am new to selenium
Not sure if Im missing something
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Main {
public static void main(String [] args) {
System.setProperty("webdriver.chrome.driver","/Users/c054148/Downloads/chromedriver");
WebDriver obj = new ChromeDriver();
obj.get("https://www.google.com");
}
} Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
at org.openqa.selenium.remote.service.DriverService$Builder.(DriverService.java:259)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.(ChromeDriverService.java:101)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 5 more
Seems you have missed the extension of the ChromeDriver. It should be chromedriver.exe
System.setProperty("webdriver.chrome.driver","/Users/c054148/Downloads/chromedriver.exe");

Firefox browser not invoking from Selenium Webdriver version 3.4.0

So here is the issue:
Basically I'm trying to invoke Firefox browser with selenium.
package basics;
import org.openqa.selenium.WebDriver;
public class BrowserInvocation {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
// There is no import option displaying when mouse over FirefoxDriver such as **import org.openqa.selenium.firefox.FirefoxDriver;**
Console output:
Exception in thread "main" java.lang.Error: Unresolved compilation
problem:
FirefoxDriver cannot be resolved to a type at
basics.firefox.main(firefox.java:19)
I'm using latest versions of all software involve (as of May 15 2017) like firefox, java, eclipse and selenium. I have use 32 bit versions and 64 bit versions. tried removing everything and setup environment again but no luck.
I have tried invoking chrome in same environment with chrome driver and so far at least I can invoke the browser.

How Caused by: java.lang.ClassNotFoundException:com.google.common.base.function will be handled in selenium?

Caused by: java.lang.ClassNotFoundException:com.google.common.base.function will be handled in selenium
got this error when running through Webdriver.
public class Logintoaccount {
#Before
public void setUp() throws Exception {
System.setProperty("webdriver.ie.driver", "d:\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
}
#Test
public void test() {
//System.setProperty("webdriver.chrome.driver", "d://chromedriver.exe");
}
}
I think you are missing the Selenium standalone server in your build path. Add the required version and you would be good to go...
selenium-server-standalone-version.jar
Add selenium-server-standalone-version.jar file in the project. the issue will be resolved
Use #BeforeTest instead of #Before, since this setup() is going to run at the beginning of the test.
Here is the solution for the problem you are facing:
You have used the Annotation as #Before. Going by the documentation of TestNG you can only use the following Annotations starting with #Before :
#BeforeSuite
#BeforeClass
#BeforeTest
#BeforeGroups
#BeforeMethod
Use the one which suits your test strategy. This will solve your issue. Do remember to import the classes​ from TestNG only.
Let me know if this helps you.

Running Seleniuem web driver 2.53.0 with Firefox 47.0

I have just started running test scripts using selenium web driver. I coded the following code as a start.
package myPackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class myTest {
public static void main(String[] args){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
}
}
When I run it as Java application, It always shows the following error message.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Just the browser opens, but the facebook page doesn't get opened.
What is the solution for this?

Error in selenium webDriver while executing the normal test case

Here is my code for selenium webDriver
package com.pack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSearchTest {
public static void main(String...args) {
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://google.com");
String appTitle = driver.getTitle();
System.out.println("Application title is :: "+appTitle);
driver.quit();
}
}
Below is the Error I am getting:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
FirefoxDriver cannot be resolved to a type
at com.pack.GoogleSearchTest.main(GoogleSearchTest.java:9)
I need to understand why I am getting that error.
Looks like you are trying to run the code that is already having compilation issues. You should be seeing a tab called "Problems", where it shows all/ any possible errors and warnings. Do you see anything in that tab? If so it will walk through the steps that you need to follow to overcome the issue.
The other option is to download a fresh copy of eclipse IDE and configure your selenium. Let me know which one worked for you.