Robotframework 如果出现错误,则运行关键字无效语法(<;字符串>;,第1行)
我不熟悉这个run关键字if方法 我想根据具体页面输入不同的号码 e、 g.如果检测到page1元素,则输入数字1,如果page2,则输入数字2Robotframework 如果出现错误,则运行关键字无效语法(<;字符串>;,第1行),robotframework,Robotframework,我不熟悉这个run关键字if方法 我想根据具体页面输入不同的号码 e、 g.如果检测到page1元素,则输入数字1,如果page2,则输入数字2 *** Settings *** Library Selenium2Library Library Collections Resource ../Resources/nine-res-work.robot *** Variables *** ${LOGIN-BUTTON-NUMBER-1} ${ANDROID-WIDGET-TE
*** 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
错误
出现语法错误,因为
Run关键字If
需要一个有效的Python条件作为第一个参数。代码中不是这样的。在本例中,假设${ANDROID-WIDGET-TEXT-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)
注意这永远不会等于通过
至于第二种方法,
页面应该包含元素,
没有返回值,它将失败,或者像往常一样继续执行。要实现您想要的,您应该使用,如果调用的关键字已通过或失败,将返回
Input Password
${Page1} = Run Keyword And Return Status Page Should Contain Element ${LOGIN-PAGE-HEARDER-page1}
Run Keyword If ${Page1} Input App Passcode
此处${Page1}
变量将为true
如果页面应包含元素
已传递,即如果登录页面标题Page1在页面上,则变量将为true
if 'view\[@resource-id="com.test.abc.work.cac:id/headerText" and @text="Enter your PIN."]' == 'PASS':
call_tap_function(LOGIN_BUTTON_NUMBER_1)
Input Password
${Page1} = Run Keyword And Return Status Page Should Contain Element ${LOGIN-PAGE-HEARDER-page1}
Run Keyword If ${Page1} Input App Passcode