Java 如何在@Before注释下调用方法
在@Before junit注释下从另一个类调用方法时遇到问题 类别1:Java 如何在@Before注释下调用方法,java,exception,selenium,junit,automated-tests,Java,Exception,Selenium,Junit,Automated Tests,在@Before junit注释下从另一个类调用方法时遇到问题 类别1: public class welcomePageTests extends SystemLogin { @Page system system; protected TestHarness getTestHarness() { return TestHarness.getInstance(); } private static final org.slf4j.L
public class welcomePageTests extends SystemLogin {
@Page
system system;
protected TestHarness getTestHarness() {
return TestHarness.getInstance(); }
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(welcomePageTests.class);
@Before
loggingToSystem();
@Test
public void shouldVerifyPageLayoutAfterFirstRunAndLayoutConsistency() throws Exception {
clickOnByLocator(welcome.homeButton);
assertThatIsDisplayedByLocator(welcome.usersButton);
mainPageLayout.assertMainPageElements(welcome);
clickOnByLocator(welcome.usersButton);
mainPageLayout.assertMainPageElements(welcome);
clickOnByLocator(welcome.loginButton);
mainPageLayout.assertMainPageElements(welcome);
}
类别2:
public class SystemLogin extends HelperMethods {
protected TestHarness getTestHarness() {
return TestHarness.getInstance();
}
@Page
system system;
public void loggingToSystem() throws InterruptedException {
goTo(PageRunner.class);
getDriver().manage().window().maximize();
Thread.sleep(2000);
system.userLogin.text("mr");
system.password.text("password");
system.signInbutton.click();
}
}
问题是我不能在@Before注释下直接调用loggingToSystem方法(而在@Test注释下则可以)
获取无效的方法声明错误
像那样努力:
@Before
public void loggingToSystem() {return loggingToSystem();}
但在这种情况下,获取的错误不能从具有void结果类型的方法返回值
有人知道问题的原因并能给我现成的解决方案吗?什么是
loggingToPanda()
返回类型
返回类型为void
的方法意味着它不会返回任何东西。如果loggingToPanda()
方法也有void
返回类型,则更改代码如下:
@Before
public void loggingToPanda() {
loggingToPanda();
}
一秒钟后,我意识到我犯了一个错误:) 这就是解决方案:
@Before
public void setup() throws InterruptedException {
loggingToPanda();
}