I have used cucumber BDD for my testcases with testng as the test engine. I have added the necessary jars in my POM.xml as mentioned below. I am using selenium 2.53 and using Firefox browser.
<!-- language: lang-xml -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
</dependency>
In runner class I have inherited the `AbstractTestNGCucumberTests` as below :
package com.cucumber.bhsibase.runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources", glue = "com.cucumber.bhsibase.party.tests")
public class TestRunner extends AbstractTestNGCucumberTests {
}
I want to launch the browser with the url, so I have added that part of the code in a method with `@BeforeTest` annotation, but nothing happens. Tried the same using `@BeforeCLass` too, but it's the same.
Please find the code below:
public class PartyBase {
// public static WebDriver driver;
ReadXML readxmlobj = new ReadXML();
final static Logger logger = Logger.getLogger(PartyBase.class);
ConfigReader reader = new ConfigReader();
public static WebDriver driver;
@BeforeTest
public void geturl() throws Exception {
logger.info("Entering the execute message");
driver = new FirefoxDriver();
logger.info("Mozzilla Browser opens");
driver.get(reader.readurls("ExpressURL"));
logger.info("Navigate to express");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
Please let me know how to proceed ahead with this. The code runs fine only if the method is called explicitly in the given step definition of each scenarios.
This issue is same if I use `@before` annotation of Junit as well.
我的testng.xml:无法用TestNG使用beforeTest注解来启动浏览器
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Party" parallel="none">
<test name = "Base Party Validation">
<classes>
<class name ="com.cucumber.bhsibase.runner.TestRunner"></class>
</classes>
</test>
</suite>
我已经加入只是我的TestRunner类。我的印象是,无论testng.xml中添加了哪个类,beforetest注释都将在其他方法之前运行。无法继续前进。我是否需要在testng.xml中添加任何其他类。
此外,这是我的testng.xml文件: <!DOCTYPE套件系统 “http://testng.org/testng-1.0.dtd”> <套件名称= “党” 平行= “无”> <测试名称= “基本方认证”> <类名= “com.cucumber.bhsibase.runner.TestRunner”> –
user3548850
能否请您编辑与XML你的问题?它会更容易阅读。感谢 – HaC
已添加在问题中。 – user3548850