在 katalon studio、Groovy 中使用 selenium 等待
因此,我一直在尝试将 selenium 中的 wait 函数实现到 katalon groovy 脚本中,但我一直收到以下行的错误
WebUI.wait.Until(FindElement(By.XPath("//*[contains(text(), 'Fund Metrics Trend']")), 10)
如果有人能告诉我为什么会出现以下错误,请看下面的代码:
原因:[0;39m [31mgroovy.lang.MissingPropertyException:没有这样的属性:等待类:com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords[0;39m [31m at Tabs Permissions.run(Tabs Permissions:54)[0;39m [31m at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)[0;39m [31m at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:321)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:312)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:291)[0;39m [31m 在com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:283)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:222)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(未知来源)[0;39m [31m 在TempTestCase1545063637352.run(TempTestCase1545063637352.groovy:22)[0;39m 2018-12-17 11:21:19.430 [1;31mERROR[0;39m [36mc.k.katalon.core.main.TestCaseExecutor -[0;39m [31m❌ 测试用例/Tabs 权限失败。[0;39m [31m原因:[0;39m [31mgroovy.lang.MissingPropertyException:没有这样的属性:等待类:com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords[0;39m [31m at Tabs Permissions.run(Tabs权限:54)[0;39m [31m 在 com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)[0;39m [31m 在 com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:321)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:312)[0;39m [31m 在com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:291)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:283)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:222)[0;39m [31m 在 com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)[0;39m [31m 在com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)[0;39m [31m at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(未知来源)[0;39m [31m at TempTestCase1545063637352.run(TempTestCase1545063637352.groovy:22)[0;39m 2018-12-17 11:21:19.430 [34mINFO [0;39m [36mc.k.katalon.core.main.TestCaseExecutor -[0;39m [39mEND 测试用例/选项卡权限
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.support.ui.WebDriverWait
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
//set Web UI delay between actions to 2 seconds Project, Settings, Execution, Default, Web UI
TestData data = findTestData('Investor/Notes')
//TestData data = findTestData('temp')
WebUI.openBrowser('')
WebDriver driver = DriverFactory.getWebDriver()
WebUI.navigateToUrl(GlobalVariable.url)
WebUI.maximizeWindow()
WebDriverWait wait = new WebDriverWait(driver, long time=10)
for (def index : (0..data.getRowNumbers() - 1)) {
WebUI.setText(findTestObject('Login/Screen Elements/input_username'), data.internallyGetValue('username', index))
WebUI.setText(findTestObject('Login/Screen Elements/input_password'), data.internallyGetValue('password', index))
WebUI.click(findTestObject('Login/Screen Elements/button_Login'))
if ((data.internallyGetValue('username', index) == 'jasmine') || (data.internallyGetValue('username', index) == 'pefadmin4') || (data.internallyGetValue('username', index) == 'pefreviewer4') || (data.internallyGetValue('username', index) == 'pefreadonly4') || (data.internallyGetValue('username', index) == 'fundaccounting4')) {
WebUI.click(findTestObject('Client/a_DFW Capital Partners'))
WebUI.click(findTestObject('Object Repository/Fund/a_DFW Capital Partners V L.P.'))
WebUI.verifyElementPresent(findTestObject('Object Repository/Tabs Permissions/a_Dashboard'), 10)
WebUI.delay(3)
WebUI.wait.Until(FindElement(By.XPath("//*[contains(text(), 'Fund Metrics Trend']")), 10)
WebUI.delay(3)
WebUI.verifyTextPresent("Fund Metrics Trend", false)
附注:这只是我的代码的上半部分,其他一切正常。
在 Katalon Studio 中,您可以将此行
WebUI.wait.Until(FindElement(By.XPath("//*[contains(text(), 'Fund Metrics Trend']")), 10)
替换为以下内容(将创建测试对象,然后实现等待):
TestObject fundMetricsTrend = new TestObject().addProperties("xpath", ConditionType.EQUALS, "//*[contains(text(), 'Fund Metrics Trend']") //this is the test object definition
WebUI.waitForElementPresent(fundMetricsTrend, 10)
注意:
您将需要导入这些
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.testobject.ConditionType
此外,您可以尝试各种
WebUI.waitFor_______()
函数以更好地满足您的需求。
您收到错误消息是因为 WebUI 类中没有“wait”。 在 Katalon Studio 中使用 wait 的一个示例是:
WebUI.waitForElementPresent(findTestObject('findTestObject('Login/Screen Elements/input_username''),
0)