When I run as TestNG, it's throwing Exception in thread main, but is running fine if it's ran as java application - selenium

I'm trying to run a basic TestNG class, but I'm getting this exception Exception in thread "main" com.beust.jcommander.ParameterException: Was passed main parameter '-d' but no main parameter was defined in your arg class
If I give main() and try with run as a java application, it's launching the browser fine. But when I run as TestNG, it's throwing Exception. I tried adding jcommander.jar manually and even tried with update maven project.
#Test
public void checking()
{
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver");
ChromeDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com");
}
}
I expect the browser has to launch and load google.com, but I'm getting Exception in thread "main" com.beust.jcommander.ParameterException: Was passed main parameter '-d' but no main parameter was defined in your arg class
at com.beust.jcommander.JCommander.initMainParameterValue(JCommander.java:936)
at com.beust.jcommander.JCommander.parseValues(JCommander.java:752)
at com.beust.jcommander.JCommander.parse(JCommander.java:340)
at com.beust.jcommander.JCommander.parse(JCommander.java:319)
at com.beust.jcommander.JCommander.<init>(JCommander.java:253)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:44)

check whether testng installed successfully and jars have been added properly in maven

Related

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

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();

Not able to run selenium test cases in jenkins

1)I have created a job in Jenkins to run selenium tests cases which consists of 5 feature files
2)I am using "Execute Shell" of Jenkins to run the test cases
where I have fired the command by going to that particular folder and running command gradle test
eg. >cd ABC
>gradle test
when I run this job by using "build Now" the test cases fails showing error
1)java.lang.IllegalStateException: Failed to load ApplicationContext
2)Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'getWebDriver' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.cosmicapp.webbrowser.FirefoxWebDriver
3)caused by java.lang.NoClassDefFoundError: Could not initialize class com.cosmicapp.webbrowser.FirefoxWebDriver
And when I run the above test cases on my machine it runs fine.
It seems there is a problem in the Jenkins project workspace or Jenkins is not able to invoke firefox or chrome browser.

Selenium Grid 2 from mac hub to windows node

I am setting up selenium grid to be able to test IE in a Virtual Machine. I am running into:
geb.driver.DriverCreationException: failed to create driver from callback
which generally means the driver is not being found. I'm pointing it to the correct location, however something isn't working. FYI refers to my hub machine's intranet IP address.
Here are my files/commands:
From Mac hub terminal:
java -jar selenium-server-standalone-2.39.0.jar -role hub
From Windows node terminal:
C:\selenium-server>java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://:4444/grid/register -browser browserName="internet explorer",version=10.0,platform=WINDOWS -Dwebdriver.ie.driver=C:\IEDriverServer.exe
My GebConfig.groovy file where the drivers are instantiated:
ie {
driver = {
DesiredCapabilities capabilities = new DesiredCapabilities().internetExplorer().
new RemoteWebDriver(new URI("http://<IP>:4444/wd/hub"), capabilities)
}
}
My stack trace is as follows:
geb.driver.DriverCreationException: failed to create driver from callback 'script13923985022291935133551$_run_closure2_closure5_closure9#557c6200'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.go(Browser.groovy:394)
at geb.Page.to(Page.groovy:184)
at geb.Browser.via(Browser.groovy:475)
at geb.Browser.to(Browser.groovy:434)
at geb.Browser.to(Browser.groovy:412)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:51)
at com.bloomhealthco.functional.LoginTestSpec.User is able to login as an administrator(LoginTestSpec.groovy:12)
Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.openqa.selenium.remote.RemoteWebDriver(java.net.URI, groovy.util.ConfigObject)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy:44)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
... 14 more
geb.driver.DriverCreationException: failed to create driver from callback 'script13923985022291935133551$_run_closure2_closure5_closure9#557c6200'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.report.PageSourceReporter.getPageSource(PageSourceReporter.groovy:42)
at geb.report.PageSourceReporter.writePageSource(PageSourceReporter.groovy:38)
at geb.report.PageSourceReporter.writeReport(PageSourceReporter.groovy:29)
at geb.report.CompositeReporter.writeReport(CompositeReporter.groovy:31)
at geb.Browser.report(Browser.groovy:775)
at geb.spock.GebReportingSpec.report(GebReportingSpec.groovy:44)
at geb.spock.GebReportingSpec.cleanup(GebReportingSpec.groovy:39)
Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.openqa.selenium.remote.RemoteWebDriver(java.net.URI, groovy.util.ConfigObject)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy:44)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
... 14 more
geb.driver.DriverCreationException: failed to create driver from callback 'script13923985022291935133551$_run_closure2_closure5_closure9#557c6200'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.openqa.selenium.remote.RemoteWebDriver(java.net.URI, groovy.util.ConfigObject)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy:44)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
... 11 more
Additionally the node can be registered with the hub:
ip:4444/grid/console screenshot
I've been searching all day and it seems this should work. Does anyone have any suggestions or know what's wrong?
Thank you in advanced.
From your stacktrace I can see that the real reason for not being able to create the driver is:
Could not find matching constructor for: org.openqa.selenium.remote.RemoteWebDriver(java.net.URI, groovy.util.ConfigObject)
Is the snipped of your GebConfig.groovy exactly the same as you have it in your file? I see that capabilities is defined as an instance of DesiredCapabilities in your snippet so I don't understand why would a config object be passed as the second parameter... I can't see it but maybe you have a typo somewhere? With Groovy config scripts you'll have issues if you mistype something as you will get a new empty ConfigObject instance instead of an error.
The second thing is that the first parameter should be an URL and not a URI if you're after using this constructor.

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

Runtime exception at selenium.start() - Could not start Selenium session: Failed to start new browser session: Error while launching browser

Followed this post -
Selenium - Could not start Selenium session: Failed to start new browser session: Error while launching browser
Error comes up at selenium.start().
I am using selenium rc(2.16) , junit(4.5) in eclipse ide.
The only way to over come this issue is to redeploy our framework in tomcat server, just restart everything.
This is the piece of code that starts selenium
private static HttpCommandProcessor proc;
public static DefaultSelenium selenium;
if (selenium == null) {
proc = new HttpCommandProcessor("localhost", 4444, browserName,
urlName);
selenium = new DefaultSelenium(proc);
**selenium.start();**
selenium.setTimeout(String.valueOf(PAGE_TIMEOUT_TIME));
selenium.useXpathLibrary("javascript-xpath");
selenium.deleteAllVisibleCookies();
}
the selenium server is already started when the execution reaches the above code.
Below is the exception that comes up when execute the tests -
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107)
at <package>.SuperClass.connectToUrl(SuperClass.java:340)
Any help or clue to resolve this thing would be appreciated!