Setting chromedriver as the default for use in Geb tests inside IntelliJ - intellij-idea

How can I set IntelliJ to recognize chromedriver as the default test browser to use for my automated Geb tests?
I have two IntelliJ projects, one that is configured and running properly hitting the targets I want, and one that has outdated code that I'm trying to bring back to life.
In the good project, when working with Geb tests, I'm able to reference the instance of Browser without actually defining it.. I.E., I can say
go('google.com')
and it works. In the project I'm trying to update, I have to define an instance of browser, and then append browser to all of my commands. Example:
browser.go('google.com')
It seems that if I don't call browser.go, it defaults to some type of phantomJs or headless (maybe htmlUnit?) browser to run the tests.
I don't see anything in the pom.xml file that would indicate to do this in EITHER of the projects, and in the good project there is no driver defined inside of the GebConfig.groovy, so I'm a little confused on where this could be set.

You configure the default browser in your GebConfig.groovy. From there you can reference the system property geb.env which could be set from Maven or Gradle. I usually build all my Geb projects with Maven, using this variable to set the default (which could still be overridden via command line). When importing the Maven project into IntelliJ IDEA, the IDE will respect the Maven setting.
For basic introduction about geb.env see the Geb manual.
In your pom.xml look for something like <geb.env>phantomjs</geb.env> and change it as needed.

Related

What is Browser Binary Manager how to use it for Selenium

I came to know recently that using 'WebDriver Binaries' manager is a good practice in Automation projects.
But not sure what is this and how to use?
Did some google searches also and got quite a lot posts around how to manage binaries; but not on why to use.
So it will be great if someone can guide on it with its benefits.
Finally Got to know about it some time back as below, thought it might be useful for other hence posting it as self Answer.
As an automation engineer, we always have to set the path for the browser binary, for this first, we need to download a binary file[driver.exe] which allows WebDriver to handle browsers. In addition, the absolute path to this binary must be set as JVM properties, as follows:
System.setProperty("webdriver.chrome.driver", "Your path to/chromedriver");
System.setProperty("webdriver.gecko.driver", "Your path/geckodriver");
Its just not about the downloading and setting properties to set the binary path but you also need to change the binaries frequently as the browser version or Selenium version changes.
I found this solution and implemented it- and That's All!
Now I don't need exe libraries anymore for the browsers!
A small maven repository made life easy.
How it works:
When working on a Maven project, you just need to add a dependency called WebDriverManager. This library will take care of everything your browser version and driver.
In order to use WebDriverManager in a Maven project, you just need to add the following dependency in your pom.xml:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.3.0</version>
</dependency>
WebDriverManager actually gets your browser version and downloads the compatible browser binary by itself to make you run your code without interruption.
Now, rather than setting the browser binaries, you just need to add below line of code in your browser manager class and that's it.
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
You're done!
The line WebDriverManager.chromedriver().setup(), does all magic for you:
It checks for the latest version of the WebDriver binary.
It downloads the WebDriver binary if it's not present on your system.
It exports the required WebDriver Java environment variables needed by Selenium.
Reference:
https://github.com/bonigarcia/webdrivermanager#webdrivermanager-as-java-dependency
When you say WebDriver binaries, I am assuming that you are talking about the WebDriver bindings or the libraries. With out adding the WebDriver binding's into your project you can't really do anything with the WebDriver interface, like you can't invoke any browser or drive any website. Either you can manually add them into your project build path or you can use any dependency management tool like Maven for getting all the WebDriver libraries into your project. You can then use them.
You can either just add the standalone server file, which would do the same job as WebdDriver bindings.
There are Third Party Driver's which we use for each of the bowser's like, chrome - chromedriver.exe, firefox - geckodriver.exe ..etc ---These are also called as WebDriver binarie's(mostly refereed as driver files).

How to setup Geb 2.0 in IntelliJ (run/debug configurations)?

I'm using Geb 2.0 (http://gebish.org/) and have downloaded the Gradle sample (https://github.com/geb/geb-example-gradle).
All works just fine on my machine with all browsers (Chrome, Firefox, ChromeHeadless).
I have imported the project in IntelliJ (latest Ultimate edition) and all normal code editing functions are working fine.
What fails is attempting to run a spec. I get an exception with the helpful hint of the path to the driver executable must be set by the webdriver.chrome.driver system property.
However, I can't figure out what to point it at. I've tried pointing at the selenium-chrome-driver-3.6.0.jar but that results in failure also.
I'm using -Dgeb.env=chrome and -Dwebdriver.chrome.driver=SOMERANDOMEPATHSHERE
Help?
The Gradle example Geb project is set up to generate the appropriately configured IntelliJ project capable fo running the specs from the IDE. Simply run ./gradlew idea and load the project by opening the geb-example-gradle.ipr file in IntelliJ instead of loading the project by importing it's Gradle build the way you do.

Intellij and Hybris Tests

Currently I'm doing the hybris 5 Developer Training Trails 5.7 - Part I - Core in Intellij and the Hybris Plugin for Intellij.
Now I'm at the point where I have to run a test class. When I'm doing it, it tells me that it's not finding a a class "de.hybris.platform.cuppy.jalo.Match".
When I'm running the same test in http://localhost:9001/test then everything works fine.
I guess I have to fix my classpath, but I don't know how. If I change the classpath of the module in "Run/Debug Configurations" to something else, then it's not working. If I change there the working directory from MODULES_DIR to the whole project path it's not working either. Now I have no ideas anymore.
Just install "Hybris Integration" plugin it will do everything automatically. You will be able to import Hybris projects just like maven or gradle based projects. That plugin provides Hybris integration into Intellij IDEA and another IDE based on it.
You can install it to your IDE directly from the repository by clicking on the "Browse Repositories" button in Settings/Plugins dialog.
You need to remove all your JAVA Build Path Problems. Then test cases should work.
In my case I had set the "power save mode" on IntelliJ. Removing it solved the problem for testing

Why IntelliJ does not show errors in java code?

How to configure intelliJ to disply errors in java code like eclipse?
see the screenshot
It does show the errors you expect, if you don't have the JUnit jar files in the classpath.
I created the exact same file as you showed in my IntelliJ and it really shows the errors:
What you might have done is that you have probably accidentally added the jar to the classpath.
Check the External Libraries as you can see in the picture. If there is no JUnit there, then it really is missing.
Now I can easily add the JUnit jar from IntelliJ and you'll notice the difference in the External Libraries:
Here it has been added under External Libraries and the error goes away.
You almost certainly already included the junit library into your IntelliJ project configuration.
This is easy to do, since IntelliJ has a quick action (alt-enter) to Add junit to classpath.
Look in Settings -> Libraries / Global Libraries and you will see it there. :)
Or you can look directly in Settings on the relevant Module -> Dependencies
Either that, or the project you are working in is configured already (perhaps via maven?) to have a junit dependency.

Selenium Grid + Maven 2

Is there a good tutorial or does anyone have experience with setting this up ?
I have a Testsuite.html which launches my tests in one browser atm. This is done in the integration-test lifecycle by the maven selenium plugin. I want to run my tests on multiple browsers. I couldn't find any documentation about selenium grid + maven. I hope somebody can help me.
Thanks in advance, kukudas
Selenium Grid and maven are really not much different than Selenium and maven.
Grid is basically a drop-in replacement for selenium-rc. In our current setup we let the automated build system use Grid. It does this by simply changing the selenium-rc url (which is normally localhost:4444) to the grid's url.
Additionally we specify the browser string (*firefox, *iexplore, *opera or whatever) as a system property on the mvn command line, which we pick up when we initialize the selenium client libraries in our code.
So the way we've done it we basically set up 4 different build projects with different browser strings.