Immutable Map Error in Selenium/JUnit with no Immutable Objects - java

I am using Java/Selenium/JUnit/ANT in Intellij and when I run my build.xml file and it gets to my Test Runner, I start to get Immutable Map errors. I do not have any Immutable Objects.
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeDriverService;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.io.IOException;
public class Auth {
public WebDriver driver;
public WebDriverWait wait;
public static void main(String[] args){
System.out.println("Let's Go.");
}
public boolean doSetup() throws IOException {
System.setProperty("webdriver.edge.driver", "C:/Path/to/MicrosoftWebDriver.exe" );
driver = new EdgeDriver();
Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
String browserName = cap.getBrowserName().toLowerCase();
//System.out.println(browserName);
if(browserName.equals("microsoftedge")) {
}
return true;
}
Then this is called in my tests as a #Before and the driver is called again in #After
#Before
public void signIn() throws Exception{
auth.doSetup();
}
#After
public void tearDown() throws Exception {
auth.driver.quit();
}
And this is throwing the following errors:
<testcase classname="adminTests.adminWorkspaceMenu" name="adminWorkspace" time="0.025">
<error message="com/google/common/collect/ImmutableMap" type="java.lang.NoClassDefFoundError">java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
at org.openqa.selenium.remote.service.DriverService$Builder.<init>(DriverService.java:249)
at org.openqa.selenium.edge.EdgeDriverService$Builder.<init>(EdgeDriverService.java:72)
at org.openqa.selenium.edge.EdgeDriverService.createDefaultService(EdgeDriverService.java:68)
at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:96)
at userTests.Auth.doSetup(Auth.java:33)
at adminTests.adminWorkspaceMenu.signIn(adminWorkspaceMenu.java:19)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
</error>
<error type="java.lang.NullPointerException">java.lang.NullPointerException
at adminTests.adminWorkspaceMenu.tearDown(adminWorkspaceMenu.java:39)
</error>
</testcase>
I would like a workaround to avoid this error, I did not experience this when I originally coded this project in Eclipse, but for a variety of reasons, I had to switch to Intellij and now I'm getting this problem.

The ImmutableMap class is from the Google Collections Library. Try adding this dependency to your project:
Maven (add to your pom.xml dependencies section):
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
Gradle (add to your build.gradle dependencies section):
testCompile group: 'com.google.collections', name: 'google-collections', version: '1.0'

Add this in your pom :
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>

Related

JUnit Cucumber Runner not finding tests

Any one know why when I run mvn clean test -Dos=android it doesn't find any tests to run? It runs find if I use the built in Cucumber or JUnit runner in Intellij. I am using Appium and Java 8.
Here are my files and folder structure
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>App</groupId>
<artifactId>Mobile-Automation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.10.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>7.10.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>26.0.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.10.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
CucumberTestRunner.java
package runner;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(features = "classpath:features", glue = {"stepdefs"}, plugin = {"pretty", "html:target/cucumber-html-report.html"})
public class CucumberTestRunner {
public CucumberTestRunner(String[] args){}
}
TestBase.java
package runner;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import pageobjects.LoginPage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;
public class TestBase {
public static AppiumDriver driver;
public static LoginPage loginPage;
static Properties props = new Properties();
public static void androidSetUp() throws MalformedURLException {
try (InputStream inputStream = ClassLoader.getSystemResourceAsStream("decivecapabilities.properties")){
props.load(inputStream);
} catch (Exception e) {e.printStackTrace();}
DesiredCapabilities androidCaps = new DesiredCapabilities();
androidCaps.setCapability("deviceName", props.getProperty("android.capability.deviceName"));
androidCaps.setCapability("udid", props.getProperty("android.capability.udid"));
androidCaps.setCapability("platformName", props.getProperty("android.capability.platformName"));
androidCaps.setCapability("platformVersion", props.getProperty("android.capability.platformVersion"));
androidCaps.setCapability("automationName", props.getProperty("android.capability.automationName"));
androidCaps.setCapability("appPackage", props.getProperty("android.capability.appPackage"));
androidCaps.setCapability("appActivity", props.getProperty("android.capability.appActivity"));
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), androidCaps);
}
public static void iosSetUp() throws MalformedURLException {
try (InputStream inputStream = ClassLoader.getSystemResourceAsStream("decivecapabilities.properties")){
props.load(inputStream);
} catch (Exception e) {e.printStackTrace();}
DesiredCapabilities iosCaps = new DesiredCapabilities();
iosCaps.setCapability("deviceName", props.getProperty("ios.capability.deviceName"));
iosCaps.setCapability("udid", props.getProperty("ios.capability.udid"));
iosCaps.setCapability("platformName", props.getProperty("ios.capability.platformName"));
iosCaps.setCapability("platformVersion", props.getProperty("ios.capability.platformVersion"));
iosCaps.setCapability("automationName", props.getProperty("ios.capability.automationName"));
//iosCaps.setCapability("app", "app-path");
driver = new IOSDriver(new URL("http://localhost:4723/wd/hub"), iosCaps);
}
public static void pageObjectInit(){
loginPage = new LoginPage(driver);
}
public static void tearDown(){
if (driver != null){
driver.quit();
}
}
}
Any insight is appreciated, and I can add post more files if needed.
By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
**/Test*.java - includes all of its subdirectories and all Java filenames that start with "Test".
**/*Test.java - includes all of its subdirectories and all Java filenames that end with "Test".
**/*Tests.java - includes all of its subdirectories and all Java filenames that end with "Tests".
**/*TestCase.java - includes all of its subdirectories and all Java filenames that end with "TestCase".
https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
By convention tests executed by Maven should end with "Test". So your class should be named RunCucumberTest.

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/HasTouchScreen

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class TestPlan {
private static final WebDriver driver = new ChromeDriver();
#BeforeSuite
public static void main(String[] args) {
// ChromeDriver location set up in Utils class
System.setProperty("webdriver.chrome.driver", Utils.CHROME_DRIVER_LOCATION);
}
#Test(testName = "Submit a WebForm")
public static void submitForm(){
driver.get(Utils.BASE_URL);
WebForm webForm = new WebForm(driver);
webForm.enterFirstName();
webForm.enterLastName();
webForm.pressSubmitButton();
}
#AfterSuite
public static void cleanUp(){
driver.manage().deleteAllCookies();
driver.close();
}
}
I can run this test please help me, having an error on this
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/HasTouchScreen
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at TestPlan.<clinit>(TestPlan.java:8)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.interactions.HasTouchScreen
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 10 more
I stumbled upon the same issue after upgrading to selenium 4.5.3 and fixed it by adding the below dependencies for chrome and firefox drivers.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>4.5.3</version>
</dependency>

Selenium with Java modules

I have a pretty simple code using selenium (sample from https://www.selenium.dev/documentation/en/):
package core;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class Main {
private static final String pathChromeDriver = "chromedriver.exe";
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", pathChromeDriver);
WebDriver driver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
try {
driver.get("https://google.com/ncr");
driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER);
WebElement firstResult = wait.until(ExpectedConditions
.presenceOfElementLocated(By.cssSelector("h3")));
System.out.println(firstResult.getAttribute("textContent"));
} finally {
driver.quit();
}
}
}
And it works fine (except that the 'main' not terminating, but the question is not about that).
Now I'm trying to make the project modular, so adding module-info.java:
module test {
requires org.seleniumhq.selenium.api;
requires org.seleniumhq.selenium.chrome_driver;
requires org.seleniumhq.selenium.support;
}
Not sure if it is important, but I'm using java 16 and maven, dependencies for selenium (version 4.0.0-alpha-5):
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>${selenium.version}</version>
</dependency>
And now execution fails with exception:
Exception in thread "main" java.lang.IllegalAccessError: superinterface check failed: class org.openqa.selenium.remote.RemoteWebDriver (in module org.seleniumhq.selenium.remote_driver) cannot access class org.openqa.selenium.internal.FindsByXPath (in module org.seleniumhq.selenium.api) because module org.seleniumhq.selenium.api does not export org.openqa.selenium.internal to module org.seleniumhq.selenium.remote_driver
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1088)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:182)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:814)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:735)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:660)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1088)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:182)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:814)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:735)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:660)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1088)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:182)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:814)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:735)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:660)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at test/core.Main.main(Main.java:19)
How can I fix it?

Apache Camel Routing with Active MQ queue in a spring boot application

I am pretty new to spring-boot, apache camel and ActiveMQ broker. I am trying to create an application which will send a message to a queue which I am hosting locally using Camel for routing.
When I run the app, I get the error :
ERROR org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[activemq:queue:myQueue] <<< in route: Route(route1)[[From[direct:firstRoute]] -> [SetBody[constant... because of Failed to resolve endpoint: activemq://queue:myQueue due to: No component found with scheme: activemq
POM:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.22.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.22.0</version>
</dependency>
MsgRouteBuilder:
public void configure() throws Exception {
from("direct:firstRoute")
.setBody(constant("Hello"))
.to("activemq:queue:myQueue");
}
application.yaml:
activemq:
broker-url: tcp://localhost:61616
user: meAd
password: meAd
MainApp.java:
package me.ad.myCamel;
import org.apache.camel.CamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import me.ad.myCamel.router.MessageRouteBuilder;
#SpringBootApplication
#EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
#EnableAspectJAutoProxy(proxyTargetClass = true)
#EnableCaching
public class MeAdApp implements CommandLineRunner {
private static final Logger LOG = LoggerFactory.getLogger(MeAdApp.class);
#Autowired
private CamelContext camelContext;
public static void main(String[] args) {
try {
SpringApplication.run(MeAdApp.class, args);
} catch (Exception ex) {
LOG.error(ex.getMessage(), ex);
}
}
#Override
public void run(String... args) throws Exception {
LOG.info("Starting MeAdApp...");
}
#Bean
public MsgRouteBuilder msgRouteBuilder() throws Exception {
MsgRouteBuilder routeBuilder = new MsgRouteBuilder();
camelContext.addRoutes(routeBuilder);
return routeBuilder;
}
}
Can anybody please point me to the right direction as to why I am getting this error ? Any help is greatly appreciated .
You need to add camel-activemq in the POM.xml file
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-activemq</artifactId>
<version>3.2.0</version>
</dependency>
Your application doesn't know the component activemq. To resolve that, you need to add the dependency of camel-activemq in your pom.xml file :
<properties>
...
<activemq.version>3.1.0</activemq.version>
</properties>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-activemq</artifactId>
<version>${activemq.version}</version>
</dependency>

Getting cucumber.runtime.CucumberException: Couldn't load plugin class: prettty while running cucmber script using Testng

Hi I am trying to run a script developed using cucumber with testng but i am getting error as follows -:
cucumber.runtime.CucumberException: Couldn't load plugin class: prettty
at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:175)
at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:165)
at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:226)
at cucumber.runtime.formatter.PluginFactory.isFormatterName(PluginFactory.java:195)
at cucumber.runtime.RuntimeOptionsFactory.addPlugins(RuntimeOptionsFactory.java:90)
at cucumber.runtime.RuntimeOptionsFactory.buildArgsFromOptions(RuntimeOptionsFactory.java:37)
at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:24)
at cucumber.api.testng.TestNGCucumberRunner.<init>(TestNGCucumberRunner.java:37)
at cucumber.api.testng.AbstractTestNGCucumberTests.setUpClass(AbstractTestNGCucumberTests.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException: prettty
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:173)
... 32 more
My Framework structure is as follows -:
framework
My pom file is as follows -:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.w2a</groupId>
<artifactId>CucumberPageObjects</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_161\bin\javac.exe</executable>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<exclude>**/*Demo.java</exclude>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.20</version>
</plugin>
</plugins>
</build>
</project>
My Runner class is as follows -:
package runner;
import java.io.File;
import java.text.SimpleDateFormat;
impo
rt java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.testng.annotations.BeforeClass;
import com.cucumber.listener.ExtentCucumberFormatter;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(
plugin= {"json:target/RunCuke/cucumber.json",
"prettty","html:target/RunCuke/cucumber.html",
"com.cucumber.listener.ExtentCucumberFormatter"},
features="/src/test/resources/features",
glue="steps",
tags= {" #Search-Cars"}
)
public class RunCuke extends AbstractTestNGCucumberTests{
#BeforeClass
public static void setup() {
SimpleDateFormat sdf=new SimpleDateFormat("ddMMyyyy_hhmmss");
Date curdate=new Date();
String strDate=sdf.format(curdate);
String filename=System.getProperty("user.dir")+"\\target\\Exten_Report"+strDate +".html";
File newFile=new File(filename);
ExtentCucumberFormatter.initiateExtentCucumberFormatter(newFile,false);
ExtentCucumberFormatter.loadConfig(new File("/src/test/resources/extent-config.xml"));
ExtentCucumberFormatter.addSystemInfo("Browser Name","Chrome");
ExtentCucumberFormatter.addSystemInfo("Browser Version","v57.0");
ExtentCucumberFormatter.addSystemInfo("Selenium Version","v3.9.1");
Map systemInfo=new HashMap();
systemInfo.put("Cucumber version", "v1.2.3");
systemInfo.put("Extent Cucumber Report version", "v1.1.0");
ExtentCucumberFormatter.addSystemInfo(systemInfo);
}
}
My utility class -:
package utils;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
public class SeleniumDriver {
private static SeleniumDriver seleniumDriver;
private static WebDriver driver;
private static WebDriverWait waitdriver;
public final static int timeout=30;
public final static int pageloadtimeout=50;
private SeleniumDriver() {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/src/test/resources/executables/chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
waitdriver=new WebDriverWait(driver, timeout);
driver.manage().timeouts().implicitlyWait(timeout , TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(pageloadtimeout, TimeUnit.SECONDS);
}
public static void setupdriver() {
if(seleniumDriver==null) {
seleniumDriver=new SeleniumDriver();
}
}
public static void tearDown() {
if(driver!=null) {
driver.close();
driver.quit();
}
seleniumDriver=null;
}
public static void openpage(String url) {
driver.get(url);
}
public static WebDriver getDriver() {
return driver;
}
}
My Step definiton class is as follows -:
package steps;
import java.util.List;
import cucumber.api.PendingException;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import pages.actions.CarsGuideHomepageactions;
import pages.actions.CarsSearchpageactions;
import utils.SeleniumDriver;
public class SearchCarsSteps {
CarsGuideHomepageactions homeactions=new CarsGuideHomepageactions();
CarsSearchpageactions searchcar=new CarsSearchpageactions();
#Given("^I am on the Home Page \"([^\"]*)\" of CarsGuide Website$")
public void i_am_on_the_Home_Page_of_CarsGuide_Website(String url) throws Throwable {
SeleniumDriver.openpage(url);
}
#When("^I move to Car For Sale Menu$")
public void i_move_to_Car_For_Sale_Menu(List<String> list) throws Throwable {
String menu=list.get(1);
System.out.println("Menu selected is "+ menu);
homeactions.movetocarsforsalemenu();
}
#And("^click on \"([^\"]*)\" link$")
public void click_on_link(String searchcar) throws Throwable {
homeactions.clickonsearchcars();
}
#And("^select carbrand as \"([^\"]*)\" from AnyMake dropdown$")
public void select_carbrand_as_from_AnyMake_dropdown(String carbrand) throws Throwable {
searchcar.selectcarmake(carbrand);
}
#And("^select \"([^\"]*)\" as car model$")
public void select_as_car_model(String carmodel) throws Throwable {
searchcar.selectcarmodel(carmodel);
}
#And("^select location as \"([^\"]*)\" from SelectLocation dropdown$")
public void select_location_as_from_SelectLocation_dropdown(String loctn) throws Throwable {
searchcar.selectcarlocation(loctn);
}
#And("^select \"([^\"]*)\" as price$")
public void select_as_price(String price) throws Throwable {
searchcar.selectcarprice(price);
}
#And("^click on Find_My_Next_Car button$")
public void click_on_Find_My_Next_Car_button() throws Throwable {
searchcar.clickonfindbutton();
}
#Then("^I should see list of searched cars$")
public void i_should_see_list_of_searched_cars() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#And("^the page title should be \"([^\"]*)\"$")
public void the_page_title_should_be(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
}
And Before and after class are -:
package steps;
import cucumber.api.java.Before;
import utils.SeleniumDriver;
public class BeforeActions {
#Before
public static void setUp() {
SeleniumDriver.setupdriver();
}
}
package steps;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import cucumber.api.Scenario;
import cucumber.api.java.After;
import utils.SeleniumDriver;
public class Afteractions {
#After
public static void teardown(Scenario sc) {
WebDriver driver =SeleniumDriver.getDriver();
if(sc.isFailed()) {
byte[] screenshot=((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
sc.embed(screenshot, "image/png");
}
SeleniumDriver.tearDown();
}
}
Feature file is as follows -:
#Search-Cars
Feature: Acceptance testing to validate Search Cars Page is working.
In order to validate that
the Search Cars page is working
Doing the Acceptance Testing
#Search-Cars-Positive
Scenario: Validate Search Cars Page
Given I am on the Home Page "https://www.carsguide.com.au" of CarsGuide Website
When I move to Car For Sale Menu
| Menu |
| Cars For Sale |
And click on "Search Cars" link
And select carbrand as "BMW" from AnyMake dropdown
And select "1 SERIES" as car model
And select location as "Australia" from SelectLocation dropdown
And select "$1,000" as price
And click on Find_My_Next_Car button
Then I should see list of searched cars
And the page title should be "Bmw 1 Series Cars Under $1000 for Sale | CarsGuide"
My extent-config.xml file is as follows -:
<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
<configuration>
<!-- report theme -->
<!-- standard, dark -->
<theme>standard</theme>
<!-- document encoding -->
<!-- defaults to UTF-8 -->
<encoding>UTF-8</encoding>
<!-- protocol for script and stylesheets -->
<!-- defaults to https -->
<protocol>https</protocol>
<!-- title of the document -->
<documentTitle>ExtentReports by vikram</documentTitle>
<!-- report name - displayed at top-nav -->
<reportName>JUnit TestRunner : Cucumber Report by vikram</reportName>
<!-- report headline - displayed at top-nav, after reportHeadline -->
<reportHeadline></reportHeadline>
<!-- global date format override -->
<!-- defaults to yyyy-MM-dd -->
<dateFormat>yyyy-MM-dd</dateFormat>
<!-- global time format override -->
<!-- defaults to HH:mm:ss -->
<timeFormat>HH:mm:ss</timeFormat>
<!-- custom javascript -->
<scripts>
<![CDATA[
$(document).ready(function() {
});
]]>
</scripts>
<!-- custom styles -->
<styles>
<![CDATA[
]]>
</styles>
</configuration>
</extentreports>
Any help to solve this issue is highly respected.
Let me know if u need other part of my code
Typo in 'prettty' in your runner class. Should be modified as below which means you will get a nice html report at the end of the test run.
plugin= {"json:target/RunCuke/cucumber.json",
"pretty","html:target/RunCuke/cucumber.html",
"com.cucumber.listener.ExtentCucumberFormatter"},

Categories

Resources