我们正在使用BDD框架,在那里我可以看到Cucumber注释@Before和@After无法正常工作。
仅使用Eclipse编辑器观察到上述问题,并且当我们在Android Studio上运行相同的代码时,我可以看到@After和@Before注释运行正常
尝试在Android Studio上使用相同的代码并且相同的代码可以正常工作,即@Before @After注释正确执行,但是当我们在Eclipse上尝试相同的代码行时。发现两个注释均通过。
TestRunner代码
package functional;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features = "Downloads/caruso-p1cms-main-1.2.70@7d2adf6cf93/Test/DBusTests/Adapter/src/test/java/Feature/TestDummy.feature"
,glue = {"xyz.gta.test.common" })
public class TestRunner {
}
StepDefinition代码:
public class StepDefinition extends TestBase {
AndroidDriver driver = super.driver;
private GtaMain gm = new GtaMain(driver);
@Given("^List of recent destinations is non-empty$")
public void list_of_recent_destinations_is_non_empty() throws Throwable {
gm.appLaucher();
ArrayList cellDataFromExcel = ExcelOperation.getCelllData("excel", "Sheet1", 0);
Iterator it = cellDataFromExcel.iterator();
while (it.hasNext()) {
gm.setValue_searchAddressOrName_HomeScreen(it.next().toString());
gm.click_selectAddress_HomeScreen();
gm.click_driveButton_OnMapScreen();
gm.click_clearRouteButton_OnMapScreen();
}
}
TestBase代码:
import cucumber.api.java.After;
import cucumber.api.java.Before;
import io.appium.java_client.android.AndroidDriver;
class TestBase {
private static String mLogFileName;
public AndroidDriver driver;
protected final NavAppController mNavAppController = new NavAppController();
protected final WebDriverManager mWebDriverManager = new WebDriverManager();
public TestBase() {
System.out.println("TestBase Constructor");
mNavAppController.restartTestFramework();
try {
driver = mNavAppController.startWebDriver();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Before
public void setUp() {
System.out.println("setUP");
mNavAppController.startNavAppAndAllowPermissions(false, false);
try {
mNavAppController.clearRouteFromMainMenu();
} catch (Exception e) {
e.printStackTrace();
}
}
}
@After
public void tearDown() {
System.out.println("tearDown");
mNavAppController.stopNavApp();
mNavAppController.stopDrivers();
mNavAppController.stopTestFramework();
mWebDriverManager.stopAppiumServer();
}
这里在StepDefnition类中扩展了TestBase,它具有Cucumber批注@After和@Before,并且根据黄瓜功能,它们应在测试之前和之后执行,但是此处这些批注是通过传递的。