ScalaTest: testing web apps with multiple browsers - selenium

I am trying to have the same integration test for a web app with multiple browsers (Chrome, Firefox, InternetExplorer, etc. one after the other).
ScalaTest plus Play has these traits AllBrowsersPerTest and AllBrowsersPerSuite. Did anyone wrote something similar but not tied to a web framework? (The web app I am testing is based on Wicket, not Play.)

I was able to solve my problem using PageObject.
PageObject uses all available browsers (i.e. those with a configured WebDriver) by default (in my case Firefox, Chrome and Internet Explorer).
These are my dependencies:
<dependency>
<groupId>org.pageobject</groupId>
<artifactId>scalatest_${scalaBinaryVersion}</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
</dependency>
I found the code of PageObjectTour helpful to get started.
Note: PageObject 0.1.0 uses its own version of ScalaTest 3.0.0 because of a bug not yet fixed in the ScalaTest trunk. So I had to remove my own dependencies to org.scalatest:scalatest.

Related

SpringBoot Selenium Automation

I have created Spring Boot web app and its working fine. Now I am writing selenium automation for my web app. I have written some test case. But when I am executing the test cases by using mvn test its giving following exception.
java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
Can someone tell me why this is error?
You might missing the jar
make sure you have httpclient 4.5.2 or higher in your class path.
refresh eclipse
Close Eclipse.
clean .m2/repository folder
Open Eclipse and Alt+F5 on project;
check option Force Update of Snapshots
Use
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.+</version>
</dependency>
and check

How to install Sikuli in IntelliJ Idea?

I want to automate a Windows app which will also become a mobile app. I am thinking of creating a test automation framework from scratch using IntelliJ.
Since the older tests are already written in Sikuli, I would like to keep them too. What are the steps for setting up Selenium and Sikuli in IntelliJ?
I would recomend you use Maven. In this case you just need to add next dependency to POM.xml
<!-- https://mvnrepository.com/artifact/com.sikulix/sikulixapi -->
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>1.1.999</version>
</dependency>

How to add Java EE Servlet API library on your compile classpath in IntelliJ

I am new to IntelliJ and I have been working on a few small projects to familiarize myself with IDE and how to develop Java web projects with it.
I recently picked up Professional Java for Web Applications to practise my web development skills and I wanted to try it because it focuses on IntelliJ rather than Eclipse.
My main issues are from not knowing my way around the IDE at all. I have come across a problem that I have been unable to figure out how to do correctly.
How do you add Java EE Servlet API library on your compile classpath ?
Where is the compile classpath located in IntelliJ ?
Any help is appreciated!
This depends on how you are managing dependencies in your project.
If you are using Maven simply add it as a dependency in your pom.xml. When IDEA sees a maven based project it will over for you to Import Changes and/or Enable Auto Import. A common JavaEE 7 maven dependency would look like this in your pom.xml:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
If you are only using an IDEA project to manage things (vs. maven, gradle etc.) then you can go into the project structure dialog, click on modules and select the module containing your web tier code. Then click on the dependencies tab. Then click on plus button (+) and add a JAR, then navigate to the JAR containing the servelet APIs that is bundled with your application server and select that.
There are another half dozen ways to set this up and exactly which one you choose depends on a lot of factors like how you want to manage provided dependencies in your project etc. Either of these methods should get you on your way though.

Using different eclipselink than bundled in glassfish-embedded-web

I use glassfish-embedded-web for integration tests inside a maven project:
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-web</artifactId>
<version>3.2-b06</version>
<scope>test</scope>
</dependency>
glassfish-embedded-web comes with Eclipselink 2.2.0, but the project requires features of 2.4. For regular deployment, this is solved by adding je required jars to glassfish's modules directory and this dependency:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.4.1</version>
<scope>provided</scope>
</dependency>
I tried also compile scope, still the embedded EL 2.2.0 is used. Adding a test scope dependency on EL 2.4.1 doesn't help. Is there any way to solve this?
Did you try to specify the maven scope test? Otherwise it will not be available while testing! To only provide this version for testing you could use maven profiles.
I see two possible solutions to this problem: either you build your own glassfish-embedded or you just use a brute force approach and modify the jar.
On the 1st approach:
After spending some time building GF I figured that even with my dilettante shell scripting skills its easier to just use the second approach instead of figuring GF code. However, if you're up for this one I'd suggest to start at oracle wiki.
On the 2nd approach: As I've mentioned above, automating this task is the best approach in my opinion (at least if you're dealing with numerous libs and continuous changes), so I wrote this script with all the necessary instructions on how to use it. After you get the new jar just install it in your local repo. I'm using Nexus so for me it was a matter of couple buttons getting pressed.
P.S.: Any comments/advices/improvements on the script are welcome.

In what maven2 repository can Google Guice be found?

As far as I understand Google Guice 2.0 is out not so long ago. But I see that central repo still has outdated 1.0 version. Please, tell where can I find maven2 repository with Google Guice 2.0.
Guice 3.0 is now available on central. You'll need the following to depend on it.
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
Sadly, they haven't uploaded source jars, and the class files have been compiled with Java 6. This may be a show-stopper for you…
Guice 2.0 is now available in the official google-maven-repository. To use it, add the following to your pom.xml inside of the <dependencies> tag (you'll need to add one if there isn't one):
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
</dependency>
You shouldn't need to, but you can add a reference to the official google-maven-repository in your pom.xml by following the instructions here.
Since I don't see Guice 2.0 in central I thought I'd include a stable repo where I found it:
https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads/
The Grails OpenID plugin references http://guice-maven.googlecode.com/svn/trunk/ but that doesn't have it (currently).
They will put it to the central repository soon, as they promised here: http://groups.google.com/group/google-guice/browse_thread/thread/6707a887ed5ef2e3
Never mind. Guice-maven is intended to provide this.
Until it reaches the central repository, I've been getting it from here: http://guice-maven.googlecode.com/svn/trunk