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