Feature File:
@tag
Feature: Test HDFC
@sceneOne1
Scenario: Test HDFC
Given I open HDFC Bank home page and click on 'Login' button
***********************************************************************************************
Step Definition:
package stepDefinitions;
import pages.MyFirstMethod;
import cucumber.api.java.en.Given;
public class MyFirstStepDefinition {
MyFirstMethod m=new MyFirstMethod();
@Given("^I open HDFC Bank home page and click on 'Login' button$")
public void iOpenHDFCBankHomePageAndClickOnLoginButton() throws Throwable {
m.clickOnElement();
}
}
******************************************************************************************
Before After:
package runnerPackage;
import org.openqa.selenium.chrome.ChromeDriver;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import pages.ConfigReadFile;
import pages.PageInstances;
public class BeforeAfter extends PageInstances{
@Before
public void runBefore()
{
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver_win32_2.26\\chromedriver.exe");
System.out.println("reached here");
driver=new ChromeDriver();
System.out.println(ConfigReadFile.URL);
driver.get(ConfigReadFile.URL);
}
@After
public void runAfter()
{
System.out.println("do nothing");
}
}
**************************************************************************************************************
Test Runner:
package runnerPackage;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features="classpath:MyFirstApp.feature",glue={"stepDefinitions"},tags={"@sceneOne1"})
public class TestRunner {
}
********************************************************************************************************************
pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.learnautomation</groupId>
<artifactId>com.learnautomation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.4</version>
</dependency>
</dependencies>
</project>
**************************************************************************************************************************
configuration file:
<ConfigurationFile.xml>
</ConfigurationFile.xml>
**********************************************************************************************************************************
config read file:
package pages;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
public class ConfigReadFile {
public static final String URL;
static {
File f=new File("C:\\Users\\dv00354652\\work\\New folder\\com.learnautomation\\ConfigurationFile.xml");
DocumentBuilderFactory docbuildFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = docbuildFactory.newDocumentBuilder();
} catch (ParserConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Document doc = null;
try {
doc = builder.parse(f);
} catch(Exception es)
{
}
URL=doc.getElementsByTagName("url").item(0).getTextContent();
System.out.println(URL);
}
}
*******************************************************************
the test runner is able to find feature file and associated hooks class as well but it's unable to execute @before,it's not opening an instance of chrome.
Any help would be appreciated