Cannot invoke "Object.getClass()" because "object" is null - Java16 - java

I am trying to setup an Appium project for learning purposes. I have created a basic structure of framework but it is throwing me following error:
net.serenitybdd.core.exceptions.StepInitialisationException: Failed to create step library for TestAppPage:Cannot invoke "Object.getClass()" because "object" is null
Below are some of my project classes:
TestAppPage.java:
package pages;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.iOSXCUITFindBy;
import net.thucydides.core.annotations.Step;
import org.openqa.selenium.WebElement;
public class TestAppPage extends AppiumBaseScreen {
#AndroidFindBy(id ="IntegerA")
#iOSXCUITFindBy(accessibility = "IntegerA")
private WebElement txtFirstNumberField;
#AndroidFindBy(id ="IntegerB")
#iOSXCUITFindBy(accessibility = "IntegerB")
private WebElement txtSecondNumberField;
#AndroidFindBy(id ="ComputeSumButton")
#iOSXCUITFindBy(accessibility = "ComputeSumButton")
private WebElement btnComputeSum;
#AndroidFindBy(id ="Answer")
#iOSXCUITFindBy(accessibility = "Answer")
private WebElement lblSumResults;
#Step("Enter 1st number")
public void enterFirstNumber(int number) {
setText(String.valueOf(number), txtFirstNumberField);
}
#Step("Enter 2nd number")
public void enterSecondNumber(int number) {
setText(String.valueOf(number), txtSecondNumberField);
}
#Step("Press sum button")
public void pressSumButton() {
btnComputeSum.click();
}
#Step("Return sum of numbers")
public String getSumOfNumbers() {
return lblSumResults.getText();
}
}
AppiumBaseScreen.java:
package pages;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.PageFactory;
import static driver.DriverBase.getAppiumDriver;
public class AppiumBaseScreen {
public AppiumBaseScreen() {
PageFactory.initElements(new AppiumFieldDecorator(getAppiumDriver()), this);
}
protected void setText(String text, WebElement element) {
click(element);
element.clear();
element.sendKeys(text);
}
protected void click(WebElement element) {
moveFocusOnElement(element);
element.click();
}
protected void moveFocusOnElement(WebElement element) {
new Actions(getAppiumDriver()).moveToElement(element).perform();
}
}
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>org.appiumpractice</groupId>
<artifactId>AppiumPractice</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<serenity.version>3.2.5</serenity.version>
<serenity.cucumber.version>3.2.5</serenity.cucumber.version>
<cucumber.version>7.3.3</cucumber.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.version}</version>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>org.jeasy</groupId>
<artifactId>easy-random-core</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
</project>
DriverBase.java:
package driver;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.options.XCUITestOptions;
import io.appium.java_client.safari.options.SafariOptions;
import java.net.URL;
public class DriverBase {
private static AppiumDriver driver;
public static void initializeDriver(URL appiumURL, XCUITestOptions capabilities) {
initIOSDriver(appiumURL, capabilities);
}
public static void initializeDriver(URL appiumURL, SafariOptions capabilities) {
initIOSDriver(appiumURL, capabilities);
}
public static AppiumDriver getAppiumDriver() {
return driver;
}
private static void initIOSDriver(URL appiumURL, XCUITestOptions capabilities) {
driver = new IOSDriver(appiumURL, capabilities);
}
private static void initIOSDriver(URL appiumURL, SafariOptions capabilities) {
driver = new IOSDriver(appiumURL, capabilities);
}
public static void closeDriver() {
driver.close();
driver.quit();
}
}
I get the above error when I try to interact with element using page factory:
element.sendKeys(text);
Everything works fine if I use the following code
driver.findElement(element).sendKeys(userName);

This is a version issue, try to downgrade JDK to 11
This fixed my issue. Hope it will fix yours too.

This issue was fixed by following two things:
Add following dependency
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version>
</dependency>
Downgrade to Java 11

Related

java: package MongoClientOptions does not exist

I am trying to upgrade the log4j version to 2.16.0 with the springboot version 2.6.2 .After upgrading My code is failing with the below error while connecting to MongoDB database .Which version of spring-data-mongodb is compatible with the springboot version 2.6.2 .Could anyone suggest which version of Mongodb is the proper version for the below Java code . Any help would be appreciated
Error:(51,27) java: package MongoClientOptions does not exist . My pom.xml as like below
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/>
</parent>
<groupId>com.sample</groupId>
<artifactId>SampleService</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SampleService</name>
<description>Project for Service</description>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<log4j2.version>2.17.0</log4j2.version>
</properties>
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-milestone</id>
<name>Spring Maven MILESTONE Repository</name>
<url>https://repo.spring.io/libs-milestone</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.2</version>
<configuration>
<arguments>
<source>1.8</source>
<target>1.8</target>
<uberJar>true</uberJar>
</arguments>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My Application Java Code :
package com.sample;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.*;
import java.security.cert.CertificateException;
#SpringBootApplication
public class Application implements CommandLineRunner {
private static final Logger LOG = LoggerFactory.getLogger(Application.class);
//private String uri;
private String database;
private String host;
private String username;
private String password;
private int port;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#Override
public void run(String... args) throws Exception {
LOG.info("Application Running.......");
}
public #Bean
com.mongodb.MongoClient mongoClient() {
MongoClientOptions.Builder mongoClientOptions = MongoClientOptions.builder().sslInvalidHostNameAllowed(true)
.sslEnabled(true).applicationName("Sample-Service");
try {
KeyStore keystore = KeyStore.getInstance("JKS");
try (InputStream in = new FileInputStream("/mnt/secrets/keystore.jks")) {
keystore.load(in, "password".toCharArray());
} catch (IOException e) {
e.printStackTrace();
} catch (CertificateException e) {
e.printStackTrace();
}
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keystore, "password".toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
mongoClientOptions.sslContext(sslContext);
} catch (NoSuchAlgorithmException | KeyStoreException | UnrecoverableKeyException | KeyManagementException e) {
e.printStackTrace();
}
MongoClientOptions mops = mongoClientOptions.build();
MongoCredential mongoCredential = MongoCredential.createCredential(username, database, password.toCharArray());
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), mongoCredential, mops);
return mongoClient;
}
// #Value("${spring.data.mongodb.uri}")
// public void setUri(String uri) {
// this.uri = uri;
// }
public String getDatabase() {
return database;
}
#Value("${spring.data.mongodb.authentication-database}")
public void setDatabase(String database) {
this.database = database;
}
public String getHost() {
return host;
}
#Value("${spring.data.mongodb.host}")
public void setHost(String host) {
this.host = host;
}
public String getUsername() {
return username;
}
#Value("${spring.data.mongodb.username}")
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
#Value("${spring.data.mongodb.password}")
public void setPassword(String password) {
this.password = password;
}
public int getPort() {
return port;
}
#Value("${spring.data.mongodb.port}")
public void setPort(int port) {
this.port = port;
}
}
Your pom.xml is asking for mongodb-driver-sync 4.2.3. Some of the classes moved or were retired in the 4.x version; for example, com.mongodb.MongoClient is now com.mongodb.client.MongoClient. Your code appears to be 3.x API compatible. You will have to spend a few minutes to rework your options setup to be compatible with the new classes. See the API docs https://mongodb.github.io/mongo-java-driver/4.2/apidocs for more.
UPDATED
I took a look and the migration to the new classes is not trivial and I hadn't used non-connection string based material in a long time so I reworked the critical parts of the code above. Note that credential, sslsettings, and connectionstring objects are designed to be built in slightly different ways which can lead to some confusion at first.
import com.mongodb.client.MongoClient; // interface
import com.mongodb.client.MongoClients; // factory
import com.mongodb.MongoClientSettings; // yes, *not* in the .client hierarchy!
import com.mongodb.MongoCredential;
import com.mongodb.ConnectionString;
MongoCredential credentials = MongoCredential.createCredential(
"USER", "ADMIN_DB", "PASSWORD".toCharArray());
String conns = String.format("mongodb://%s:%d/?replicaSet=rs0", "localhost", 27017);
MongoClientSettings.Builder mcsb = MongoClientSettings.builder();
MongoClientSettings mcs = mcsb
.applicationName("Sample-Service")
.credential(credentials)
.applyToSslSettings(sslb ->
sslb.enabled(true)
.invalidHostNameAllowed(true))
.applyConnectionString(new ConnectionString(conns))
.build();
MongoClient client = MongoClients.create(mcs);
I think you should upgrade your dependencies. Please see the version and pom
Please try:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.3.0</version>
</dependency>
<!-- reactive: Do you really need it? -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.4.0</version>
</dependency>
Suggestion
If you use spring-boot, and you can try org.springframework.boot:spring-boot-starter-data-mongodb to auto config.

Appium Maven: java.lang.RuntimeException: java.lang.NoSuchMethodException: jdk.proxy2.$Proxy10.proxyClassLookup()

When running test from terminal mvn test, Im encountering the following error
Running test via Intellij testng plugin works as expected
Only when running via a mvn command
Java: 15.0.2
Maven: 3.8.2
Appium Desktop: v1.21.0
java.lang.RuntimeException: java.lang.NoSuchMethodException: jdk.proxy2.$Proxy10.proxyClassLookup()
at Registration.NewRegistrationTest.RegisterUser(NewRegistrationTest.java:15)
`
Base Test
package Pages.base;
public class BaseTest {
public static AppiumDriver<MobileElement> driver;
public CommonUtils util = new CommonUtils();
#BeforeSuite
public void installAppBeforeSuite(){
driver = util.getAndroidDriver();
driver.installApp("{AppLocation}");
}
#BeforeClass
public void launchApp(){
if (driver==null) {
System.out.println("Driver Null Creating New Driver");
driver = util.getAndroidDriver();
}
driver.launchApp();
}
// #AfterClass
// public void closeApp() {
// driver.terminateApp("com.getmyboat_v1");
// }
}
Base Page
package Pages.base;
import io.appium.java_client.AppiumDriver;
import java.util.concurrent.TimeUnit;
public class BasePage {
public static AppiumDriver<MobileElement> driver;
public WebDriverWait wait;
public BasePage(AppiumDriver<MobileElement> driver) {
this.driver=driver;
this.wait= new WebDriverWait(this.driver,10);
}
public void hideKeyboard(){
driver.hideKeyboard();
}
public void showKeyboard(){
driver.getKeyboard();
}
public void pressEnter(){
((AndroidDriver)driver).pressKey(new KeyEvent(AndroidKey.ENTER));
}
}
Page Object
package Pages.common;
import Pages.base.BasePage;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.openqa.selenium.support.PageFactory;
import java.time.Duration;
public class footerComponent extends BasePage {
public footerComponent(AppiumDriver driver) {
super(driver);
PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(30)), this);
}
#AndroidFindBy(uiAutomator = "new UiSelector().text(\"Account\")")
public MobileElement accountBtn;
#AndroidFindBy(uiAutomator = "new UiSelector().text(\"Search\")")
public MobileElement searchBtn;
#AndroidFindBy(uiAutomator = "new UiSelector().text(\"Inbox\")")
public MobileElement inboxBtn;
#AndroidFindBy(uiAutomator = "new UiSelector().text(\"Calendar\")")
public MobileElement calendarBtn;
public void clickAccount() {
accountBtn.click();
}
public void clickSearch() {
searchBtn.click();
}
public void clickInbox() {
inboxBtn.click();
}
public void clickCalendar() {
calendarBtn.click();
}
}
POM.xml
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<aspectj.version>1.8.10</aspectj.version>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.5.1</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<testFailureIgnore> true </testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>/Users/adambethlehem/IdeaProjects/Appium/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>

How to run #BeforeSuite and #AfterSuite methods defined in another class before the execution of the step def class starts?

Can someone explain why I am not able to run this cucumber, testng project? Below is the code:
TestRunner.java:
package runner;
import org.testng.annotations.Test;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
#CucumberOptions(
features = {"src/test/resources/features"},
glue = "steps",
plugin = {"pretty", "json:target/json-report/cucumber.json"},
dryRun = false,
monochrome = true
)
#Test
public class TestRunner extends AbstractTestNGCucumberTests {
}
GithubLoginPageSteps.java:
package steps;
import static org.testng.Assert.fail;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class GithubLoginPageSteps extends CommonSteps {
private WebDriver driver;
public GithubLoginPageSteps(CommonSteps commonSteps) {
System.out.println("Inside CitiHomePageSteps() ");
this.driver = commonSteps.getDriver();
}
#Given("I am on the {string}")
public void i_am_on_the(String githubHomePageUrl) throws InterruptedException {
System.out.println(githubHomePageUrl);
driver.get(githubHomePageUrl);
Thread.sleep(2000);
}
#When("the user enters the right {string} and {string}")
public void the_user_enters_the_right_and(String username, String pwd) {
driver.findElement(By.xpath("//*[#id=\"login_field\"]")).click();
driver.findElement(By.xpath("//*[#id=\"login_field\"]")).sendKeys(username);
driver.findElement(By.xpath("//*[#id=\"password\"]")).click();
driver.findElement(By.xpath("//*[#id=\"password\"]")).sendKeys(pwd);
}
#When("the user clicks on the sign on button")
public void the_user_clicks_on_the_sign_on_button() throws InterruptedException {
driver.findElement(By.xpath("//*[#id=\"login\"]/div[4]/form/div/input[12]")).click();
Thread.sleep(000);
}
#Then("the user is navigated to the {string}")
public void the_user_is_navigated_to_the(String githubDashboardUrl) {
String actualUrl = driver.getCurrentUrl();
String expectedUrl = githubDashboardUrl;
System.out.println("Actual url is:"+ actualUrl);
System.out.println("Expected url is:"+ expectedUrl);
driver.quit();
if(!actualUrl.equals(expectedUrl)) {
fail("Dashboard url didn't match the expected url:"+ expectedUrl);
}
}
}
CommonSteps.java:
package steps;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import io.cucumber.java.Scenario;
public class CommonSteps {
private WebDriver driver;
#BeforeSuite
public void setUp() {
System.setProperty("webdriver.chrome.driver", "src/test/resources/webdriver/chromedriver.exe");
driver = new ChromeDriver();
System.out.println("Inside #BeforeSuite hook");
}
#AfterSuite
public void tearDown(Scenario scenario) {
System.out.println("Inside #AfterSuite hook");
driver.quit();
}
public WebDriver getDriver() {
System.out.println("Inside getDriver()");
return this.driver;
}
}
testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="runner.TestRunner"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
pom.xml:
<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.shri.automation</groupId>
<artifactId>Cucumber-TestNg2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Cucumber-TestNg2</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.10.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>6.10.4</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-beta-4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>6.10.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>2.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<skip>false</skip>
<outputDirectory>${project.build.directory}/masterthought-report</outputDirectory>
<cucumberOutput>${project.build.directory}/json-report/cucumber.json</cucumberOutput>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
GithubLoginFeaturePage.feature:
Feature: Github Login Page
Scenario Outline: Github Login
Given I am on the '<GithubLoginPage_url>'
When the user enters the right '<username>' and '<password>'
And the user clicks on the sign on button
Then the user is navigated to the '<Github_dashboard_url>'
Examples:
|GithubLoginPage_url|username|password|Github_dashboard_url|
|https://github.com/login|abc#gmail.com|1234|https://github.com/|
[Project structure link][1]
[1]: https://i.stack.imgur.com/qAFom.png
The error I get is:
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebDriver.get(String)" because "this.driver" is null
at steps.GithubLoginPageSteps.i_am_on_the(GithubLoginPageSteps.java:27)
I think I found the reason why that 'driver is null error' was coming in the GithubLoginPageSteps. Because in the testng.xml file I forgot to add the inside the of the named 'Test'. And then I need to make the 'driver' variable in CommonSteps as static so that the same copy is used across all instances of the CommonSteps class.
This is necessary because two instances of the CommonSteps would be created when I now run the testng.xml file, one to run the CommonSteps.java class defined in the testng.xml where the 'driver' would be initialized and then in the GithubLoginSteps.java I am also injecting the CommonSteps class instance using the cucumber picocontainer and then use this to get the 'driver'. So you see if I don't declare the driver as static then there is no way 'driver' would be initialized in the CommonSteps.java and it would remain as null.
Also I found that I don't even need to extend the CommonSteps class inside the GithubLoginPageSteps class and the thread-count attribute in the testng.xml is also redundant.
With these changes I tried to run the code and it worked!

org.openqa.selenium.NoSuchSessionException: Session ID is null. -getting this error in automation (using testng,selenium,java) [duplicate]

This question already has answers here:
org.openqa.selenium.NoSuchSessionException: Unable to find session with ID error testing with Behat/Mink and Selenium2Driver in docker container
(2 answers)
org.openqa.selenium.NoSuchSessionException: no such session error in Selenium automation tests using ChromeDriver Chrome with Java
(1 answer)
WebDriverError: no such session error using ChromeDriver Chrome through Jenkins and Selenium
(5 answers)
Closed 2 years ago.
My files are given below. please help me in parallel execution in same machine. Multiple Browsers are opening but URL in one browser is not getting added also. and this is what error is coming which is mentioned in output .Thanks in advance.
This is testng file.
-----## testng##-----
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="BOC UI AUTOMATION">
<test name="BOC Feature Testing" parallel="methods" thread-count="2">
<classes>
<class name="runner.loginPageRunner"></class>
<class name="runner.B2BSmokeRunner"></class>
</classes>
</test>
</suite>
----------
This is driver settings file where i am selecting driver of browser.
## Driversetting ##
----------
package base;
import java.io.File;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.Dimension;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import utils.FileReference;
public class DriverSettings
{
/**
* Overloaded browser setup with browser name and time-out being
* sent as parameter
* #param browserName : name of the browser (like: firefox, ie, chrome) case insensitive
* #param timeUnitInSecond : Timeout second for implicit time-out
*/
public void setUpDriver(String browserName, int timeUnitInSecond)
{
final FirefoxOptions options = new FirefoxOptions();
switch(browserName.trim().toLowerCase())
{
case "firefox" :
System.setProperty("webdriver.gecko.driver", FileReference.driversFilePath+File.separator+"geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
options.addPreference("browser.popups.showPopupBlocker", false);
options.addPreference("security.sandbox.content.level", 5);
Driver.driver = new FirefoxDriver(options);
break;
case "chrome" :
System.setProperty("webdriver.chrome.driver", FileReference.driversFilePath+File.separator+"chromedriver.exe");
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", FileReference.download);
ChromeOptions option = new ChromeOptions();
option.setExperimentalOption("prefs", chromePrefs);
option.setAcceptInsecureCerts(true);
Driver.driver = new ChromeDriver(option);
break;
default :
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "\\geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
options.addPreference("browser.popups.showPopupBlocker", false);
options.addPreference("security.sandbox.content.level", 5);
Driver.driver = new FirefoxDriver(options);
break;
}
setWait(timeUnitInSecond);
setBrowserAtMaxSize();
}
/**
* Sets the implicit time out as parameter
* #param timeUnitInSecond : Timeout second for implicit time-out
*/
protected static void setWait(int timeUnitInSecond)
{
Driver.driver.manage().timeouts().implicitlyWait(timeUnitInSecond, TimeUnit.SECONDS);
}
/**
* Sets the browser at maximum size of the screen
*/
protected void setBrowserAtMaxSize()
{
Driver.driver.manage().window().maximize();
}
/**
* Closes the driver, deletes all cookies
*/
public void closeDriver()
{
// Driver.driver.close();
Driver.driver.quit();
}
public void closeWindow()
{
Driver.driver.close();
}
}
----------
----------##Driver## ----------
package base;
import org.openqa.selenium.WebDriver;
public class Driver
{
public static WebDriver driver;
}
----------
##Browser##
----------
package base;
import org.dom4j.DocumentException;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchSessionException;
import utils.LoadEnvironment;
public class Browser {
private DriverSettings driverSetting;
protected static int timeToWait = 30;
public Browser() throws DocumentException
{
LoadEnvironment.loadProperties();
String browserName=LoadEnvironment.browser;
driverSetting = new DriverSettings();
driverSetting.setUpDriver(browserName, timeToWait);
}
public Browser(String browserName)
{
driverSetting = new DriverSettings();
driverSetting.setUpDriver(browserName, timeToWait);
}
public Browser(String browserName, int timeUnitInSecond)
{
driverSetting = new DriverSettings();
timeToWait = timeUnitInSecond;
driverSetting.setUpDriver(browserName, timeUnitInSecond);
}
public void close()
{
try
{
driverSetting.closeDriver();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public static void navigateTo(String URL)
{
Driver.driver.get(URL);
}
public void refresh()
{
Driver.driver.navigate().refresh();
}
/**
* Read the URL of the current page
* #return : String URL
*/
public String getCurrntUrl()
{
return Driver.driver.getCurrentUrl();
}
public static void scrollToBottomOfThePage() throws InterruptedException {
Thread.sleep(100);
JavascriptExecutor js = ((JavascriptExecutor) Driver.driver);
js.executeScript("window.scrollTo(0,document.body.scrollHeight)");
Thread.sleep(400);
}
public static boolean isBrowserReachable()
{
boolean browserReachable=true;
try {
Driver.driver.getTitle();
}catch(NoSuchSessionException e)
{
browserReachable=false;
}
return browserReachable;
}
}
----------
##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>B2BUI_Automation</groupId>
<artifactId>com.softwareag</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<aspectj.version>1.9.4</aspectj.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<suite.file>testng.xml</suite.file>
<browser>chrome</browser>
<tagsToRun></tagsToRun>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
-Dcucumber.options="--plugin utils.CustomCucumberAfterStepListener --plugin io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm ${tagsToRun}"
</argLine>
<suiteXmlFiles>
<suiteXmlFile>${suite.file}</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<browser>${browser}</browser>
</systemPropertyVariables>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/allure-results</directory></fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.10.0</version>
<configuration>
<resultsDirectory>../allure-results</resultsDirectory>
</configuration>
</plugin>
</plugins>
</reporting>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.4.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-cucumber4-jvm</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.5.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jaxen/jaxen -->
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.6</version>
</dependency>
</dependencies>
</project>
Output
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'SAG-DMPJ622', ip: '10.91.56.203', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.5'
Driver info: driver.version: RemoteWebDriver

When I use Cucumber (Scenario scenario) parameter in step def method,error displayed declared with 1 parameters. the gherkin step has 0 arguments

I wrote the following feature step to take screen shot after failed scenario and close the browser. On the Step Defs method when I use (Scenario scenario) parameter and Run it But it generates an error message.
Following Feature Step I wrote:
And I close the browser
Following is the code I have written in Step Definition file for that step:
#And("^I close the broswer$")
public void i_Close_The_Broswer(Scenario scenario ) throws Exception {
if (scenario.isFailed()) {
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
Error Message displays after run:
cucumber.runtime.CucumberException: Arity mismatch: Step Definition
'stepDefinations.LoginPageStepDefs.i_Close_The_Broswer(Scenario) in
file:/C:/Users/thaider/eclipse-workspace/AcWs_Automation/target/test-
classes/' with pattern [^I close the broswer$] is declared with 1
parameters. However, the gherkin step has 0 arguments [].
Test Base Class:
package utilities;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chrome.ChromeDriver;
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
public class TestBase {
public static WebDriver driver;
public static Properties prop;
public TestBase() {
try {
prop = new Properties();
FileInputStream fis = new FileInputStream(
"C:/Users/thaider/eclipse-workspace/AcWs_Automation/src/test/java/config/config.properties");
prop.load(fis);
} catch (IOException e) {
e.getMessage();
}
}
public static void initialization() {
String browserName = prop.getProperty("browser");
if(browserName.equals("chrome")){
//System.setProperty("webdriver.chrome.driver", "src/main/resources/Driver/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", prop.getProperty("webdriver.chrome.driver"));
// System.setProperty("log4j.configurationFile", prop.getProperty("log4j2ConfigFile"));
driver = new ChromeDriver();
}
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(TestUtil.IMPLICIT_WAIT, TimeUnit.SECONDS);
driver.get(prop.getProperty("url"));
}
public static void closeSession() {
driver.quit();
}
}
Login Page Step Definition File:
package stepDefinations;
import java.awt.Window;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriverException;
import cucumber.api.PendingException;
import cucumber.api.Scenario;
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 pageObject_OR.AcceptContinue;
import pageObject_OR.LoginPage;
import utilities.TestBase;
import utilities.WindowsHandle;
import org.openqa.selenium.WebElement;
public class LoginPageStepDefs extends TestBase {
AcceptContinue acceptPage;
LoginPage loginPage;
WindowsHandle windowHandle;
#Given("^I want to open a browser$")
public void i_want_to_open_a_browser() throws Exception{
TestBase.initialization();
}
#Then("^I click on Accept & Continue$")
public void i_click_on_Accept_Continue() throws Exception{
acceptPage = new AcceptContinue();
acceptPage.clickAcceptContinue();
}
#Then("^I validate seal logo is displayed$")
public void i_validate_seal_logo_is_displayed() throws Exception {
loginPage = new LoginPage();
Thread.sleep(3000);
loginPage.validateCrmImage();
}
#Then("^I am in the ACWS login page as a CS User$")
public void i_am_in_the_ACWS_login_page_as_a_CS_User() throws Exception {
// Write code here that turns the phrase above into concrete actions
loginPage = new LoginPage();
loginPage.loginToHomePage("Testcs", "test123");
}
#And("^I close the broswer$")
public void i_Close_The_Broswer(Scenario scenario ) throws Exception {
if (scenario.isFailed()) {
byte[] screenshot = ((TakesScreenshot)
driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
TestBase.closeSession();
}
pom.xml File:
<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>AcWs_Automation</groupId>
<artifactId>AcWs_Automation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- REPORTING DEPENDENCIES ARE BELOW -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<testFailureIgnore>true </testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.15.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>ExecuteAutomation</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- Project Selenium, Junit, Apache POI Dependecy Below -->
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version> 3.12.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16-beta2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>openxml4j</artifactId>
<version>1.0-beta</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
<dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId>
<version>2.11.2</version> </dependency> -->
<!-- BELOW DEPENDECIES HAS BEEN COMMENTED OUT FOR DUPLIATION -->
<!-- <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId>
<version>3.9</version> </dependency> <dependency> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId> <version>3.9</version> </dependency>
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-scratchpad</artifactId>
<version>3.9</version> </dependency> <dependency> <groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId> <version>1.1</version> </dependency>
<dependency> <groupId>org.apache.poi</groupId> <artifactId>openxml4j</artifactId>
<version>1.0-beta</version> </dependency> -->
</dependencies>
Project Structure and Feature File
From the Cucumber API for Scenario (https://github.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/cucumber/api/Scenario.java) :
Before or After Hooks that declare a parameter of this type will receive an instance of this class
Note that it says only the Before and After hooks - not the Step definitions #And, #Given, #When, #Then. Those expect only the arguments specified in the line expression.

Categories