我试图通过groovy脚本使网站自动化,但是我陷入了试图在另一个groovy脚本中调用方法的问题。我正在尝试在LoginWebsite()
groovy脚本的Login
groovy脚本上调用MainControl
,但是我不断收到以下错误Cannot invoke method LoginWebsite() on null object
我不确定自己在做什么错,需要帮助
登录类:
class Login
{
def projectContext = context.testCase.testSuite.project.context;
def driver = projectContext.driver;
WebDriverWait wait = new WebDriverWait(driver, 10);
public boolean LoginWebsite()
{
try
{
WebElement element = driver.findElement(By.id("mainLoginBtn"));
(new Actions(driver)).moveToElement(element).perform();
wait.until(ExpectedConditions.elementToBeClickable(element));
Thread.sleep(2000);
element.click();
Thread.sleep(2000);
driver.findElement(By.id("userId")).sendKeys(testRunner.testCase.testSuite.getPropertyValue("ID"));
driver.findElement(By.id("password")).sendKeys(testRunner.testCase.testSuite.getPropertyValue("pin"));
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("loginBtn"))));
driver.findElement(By.id("loginBtn")).click();
Thread.sleep(3000);
return true;
}
catch (Exception ex){
log.info(ex.getMessage());
return false;
}
return false;
}
}
context.setProperty("LoginStep",new Login())
MainControl类
for(String website : wList)
{
//ChromeDriver property setters are global variables
//CD - ChromeDriver CDL - ChromeDriverLocation
//website is website URL's
System.setProperty(com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("CD"),com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("CDL"));
WebDriver driver = new ChromeDriver();
def projectContext = context.testCase.testSuite.project.context;
projectContext.driver = driver;
driver.navigate().to(website);
Thread.sleep(2000);
def lib = testRunner.testCase.testSuite.project.getTestSuiteByName("Automation_groovy").getTestCaseByName("Website_Auto").getTestStepByName("Login")
lib.run(testRunner,context)
def login = context.LoginStep;
boolean s = login.LoginWebsite();
if(s == true)
{
log.info(true)
}
}