我是这个run关键字if方法的新手。
我想根据特定页面输入其他号码。
例如,如果检测到page1元素,则输入数字1;如果page2,则输入数字2。
*** Settings ***
Library Selenium2Library
Library Collections
Resource ../Resources/nine-res-work.robot
*** Variables ***
${LOGIN-BUTTON-NUMBER-1} ${ANDROID-WIDGET-TEXT-VIEW}\[@resource-id="com.test.abc.work.cac:id/btn_number" and @text="1"]
${LOGIN-BUTTON-NUMBER-2} ${ANDROID-WIDGET-TEXT-VIEW}\[@resource-id="com.test.abc.work.cac:id/btn_number" and @text="2"]
${LOGIN-BUTTON-NUMBER-3} ${ANDROID-WIDGET-TEXT-VIEW}\[@resource-id="com.test.abc.work.cac:id/btn_number" and @text="3"]
${LOGIN-PAGE-HEARDER-page1} ${ANDROID-WIDGET-TEXT-VIEW}\[@resource-id="com.test.abc.work.cac:id/headerText" and @text="Enter your PIN."]
${LOGIN-PAGE-HEARDER-page2} ${ANDROID-WIDGET-TEXT-VIEW}\[@resource-id="com.test.abc.work.cac:id/headerText" and @text="Enter your passcode."]
*** Keywords ***
Smart Card Login
Run Keyword If ${LOGIN-PAGE-HEARDER-page1} == 'PASS' Tap ${LOGIN-BUTTON-NUMBER-1}
Run Keyword If ${LOGIN-PAGE-HEARDER-page2} == 'PASS' Tap ${LOGIN-BUTTON-NUMBER-2}
*** Test Cases ***
Test 1
Launch Application
Smart Card Login
错误
Test 1 | FAIL |
Evaluating expression '//android.widget.TextView[@resource-id="com.test.abc.work.cac:id/headerText" and @text="Enter your PIN."] == 'PASS'' failed: SyntaxError: invalid syntax (<string>, line 1)
我尝试了另一种方法,这次没有错误,但是tap操作没有执行。
*** Variables ***
${LOGIN-BUTTON-NUMBER-1} ${ANDROID-WIDGET-TEXT-VIEW}\[@resource-id="com.test.abc.work.cac:id/btn_number" and @text="1"]
${LOGIN-BUTTON-NUMBER-2} ${ANDROID-WIDGET-TEXT-VIEW}\[@resource-id="com.test.abc.work.cac:id/btn_number" and @text="2"]
${LOGIN-BUTTON-NUMBER-3} ${ANDROID-WIDGET-TEXT-VIEW}\[@resource-id="com.test.abc.work.cac:id/btn_number" and @text="3"]
${LOGIN-PAGE-HEARDER-page1} ${ANDROID-WIDGET-TEXT-VIEW}\[@text="Enter your PIN."]
${LOGIN-PAGE-HEARDER-page2} ${ANDROID-WIDGET-TEXT-VIEW}\[@text="Enter your passcode."]
*** Keywords ***
Input App Passcode
Tap ${LOGIN-BUTTON-NUMBER-2}
*** Test Cases ***
Launch App
Open Nine Folders Application
Sleep 5s
Input Password
${Page1} = Page Should Contain Element ${LOGIN-PAGE-HEARDER-page1}
Run Keyword If '${Page1}' == 'PASS' Input App Passcode
您遇到语法错误,因为Run Keyword If
期望有效的Python条件作为第一个参数。在您的代码中情况并非如此。在您的情况下,这就是发生的情况,假设${ANDROID-WIDGET-TEXT-VIEW}
仅view
在此示例中:
Run Keyword If ${LOGIN-PAGE-HEARDER-page1} == 'PASS' Tap ${LOGIN-BUTTON-NUMBER-1}
这是
Run Keyword If view\[@resource-id="com.test.abc.work.cac:id/headerText" and @text="Enter your PIN."] == 'PASS' Tap ${LOGIN-BUTTON-NUMBER-1}
这等效于以下Python代码:
if view\[@resource-id="com.test.abc.work.cac:id/headerText" and @text="Enter your PIN."] == 'PASS':
call_tap_function(LOGIN_BUTTON_NUMBER_1)
那里有很多无效字符,因为该字符串未包含在中'
。因此正确的应该是:
Run Keyword If '${LOGIN-PAGE-HEARDER-page1}' == 'PASS' Tap ${LOGIN-BUTTON-NUMBER-1}
它将转换为:
if 'view\[@resource-id="com.test.abc.work.cac:id/headerText" and @text="Enter your PIN."]' == 'PASS':
call_tap_function(LOGIN_BUTTON_NUMBER_1)
请注意,这永远不会等于PASS
。
至于第二种方法,Page Should Contain Element
它没有返回值,它将失败或执行将照常进行。要实现所需的功能,您应该使用“运行关键字并返回状态”,如果被调用的关键字已通过或失败,它将返回。
Input Password
${Page1} = Run Keyword And Return Status Page Should Contain Element ${LOGIN-PAGE-HEARDER-page1}
Run Keyword If ${Page1} Input App Passcode
如果传递了${Page1}
变量,这里就是变量,也就是如果登录页面标题page1在页面上。true
Page Should Contain Element
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句