我必须将Gherkin与Katalon Studio集成,因此我在Groovy中创建了一个基本场景的测试项目,并在Katalon Studio中导入了该项目。当我在Katalon Studio中执行Junit测试时,它会抛出错误:"在以下期间发生内部错误:"启动TestGroovy"。 显示java.lang.NullPointerException&#34 ;.我已经添加了必要的库。
注意:测试在Eclipse中成功通过。
在Katalon上运行Junit测试需要多少额外的东西?
TestGroovy.groovy
package groovyKat
import org.junit.runner.RunWith
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "Features"
,glue= ["groovyKat"]
)
class TestGroovy {
}
TestGroovyStepDef.groovy
package groovyKat
import java.util.concurrent.TimeUnit
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver
import cucumber.api.java.en.Given
import cucumber.api.java.en.Then
import cucumber.api.java.en.When
class TestGroovyStepDef {
static WebDriver driver;
@Given('^A User is on Demoqa\\.com$')
void a_User_is_on_Demoqa_com() throws Throwable {
System.setProperty('webdriver.gecko.driver','D:/geckodriver/geckodriver.exe');
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get('http://www.store.demoqa.com');
}
@When('^User clicks on MyAccount link$')
void user_Clicks_on_MyAccount_link() throws Throwable {
driver.findElement(By.xpath('.//*[@id="account"]/a')).click();
}
@When('^User enters username "(.*)" and password "(.*)"$')
void user_enters_username_and_password(String username,String password) throws Throwable {
driver.findElement(By.id('log')).sendKeys(username);
driver.findElement(By.id('pwd')).sendKeys(password);
driver.findElement(By.id('login')).click();
}
@Then('^Message displayed Login Successfully$')
void message_displayed_Login_Successfully() throws Throwable {
System.out.println('Login Successfully');
}
}
testSample.feature
Feature: Login feature
Scenario: Successful Login with Valid Credentials
Given A User is on Demoqa.com
When User clicks on MyAccount link
And User enters username "xxxxxx" and password "xxxxxxx"
Then Message displayed Login Successfully
答案 0 :(得分:1)
使用当前版本的Katalon(5.4.1),无法运行此脚本,即以JUnit(Cucumber)-Test实现。
您必须重写Katalon Studio的测试。
请参阅https://forum.katalon.com/discussion/1976/how-can-i-import-selenium-scripts-in-katalon