Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 机器人框架中的嵌套循环_Java_Selenium_For Loop_Nested_Robotframework - Fatal编程技术网

Java 机器人框架中的嵌套循环

Java 机器人框架中的嵌套循环,java,selenium,for-loop,nested,robotframework,Java,Selenium,For Loop,Nested,Robotframework,我需要在Robot框架中创建一个嵌套循环。 你能帮我做吗 ${contents}= Get File ${file path} @{lines}= Split to lines ${contents} ${matched elements}= Get Webelements ${LABEL PORTAIL XPATH } : FOR ${element} IN @{matched elements} \ ${text}=

我需要在Robot框架中创建一个嵌套循环。 你能帮我做吗

${contents}=    Get File    ${file path}
 @{lines}=    Split to lines    ${contents}
 ${matched elements}=    Get Webelements    ${LABEL PORTAIL XPATH }
 : FOR    ${element}    IN    @{matched elements}
 \    ${text}=    Get Text    ${element}
 \    : FOR    ${line}    IN    @{lines}
 \    Run Keyword If    '${text}' == '${line}'    Log    '${text} matched'
我需要一个嵌套循环,它将文件中的所有
${text}
与所有
@{lines}
进行比较


提前感谢

如果没有包含内部循环的自定义关键字,这是不可能的。 见文件:


我想说的是,这种逻辑应该总是使用某种更强的语言(python、java…)编写,然后从RF调用。

RF中没有嵌套循环;这只能通过在外部循环中调用具有内部循环的关键字来实现

但是,在您的特定情况下,您可以不使用它-因为您希望匹配完整的行,这是可行的,应该包含:

${contents}=    Get File    ${file path}
@{lines}=    Split to lines    ${contents}
${matched elements}=    Get Webelements    ${LABEL PORTAIL XPATH }
: FOR    ${element}    IN    @{matched elements}
\  ${text}=     Get Text    ${element}
\  ${present}=  Run Keyword And Return Status    Should Contain    ${lines} 
${text}
\    Run Keyword If  ${present}    Log    '${text} matched'

如果您正在寻找部分匹配-即
${text}
成为
${lines}
成员的一部分,则不可能出现这种情况。

嵌套for循环

不直接支持嵌套for循环,但可以在for循环中使用用户关键字,并在那里使用另一个for循环

*** Keywords ***
Handle Table
    [Arguments]    @{table}
    :FOR    ${row}    IN    @{table}
    \    Handle Row    @{row}

Handle Row
    [Arguments]    @{row}
    :FOR    ${cell}    IN    @{row}
    \    Handle Cell    ${cell}

引用自:

从4.0版本开始,Robot框架(最后:)支持嵌套for循环。
因此,使用新的
FOR
语法,问题中的代码将是:

${contents}=  Get File    ${file path}
@{lines}=     Split to lines    ${contents}
${matched elements}=    Get Webelements    ${LABEL PORTAIL XPATH }
FOR    ${element}    IN    @{matched elements}
    ${text}=    Get Text    ${element}
    FOR    ${line}    IN    @{lines}
        Run Keyword If    '${text}' == '${line}'    Log    '${text} matched'
    END
END

4.0版本还提供了
IF/ELSE
流量控制,因此可以使内部循环在第一次匹配时中断:

    FOR    ${line}    IN    @{lines}
        IF    '${text}' == '${line}'
            Log    '${text} matched'
            Exit For Loop
        END
    END
,而不是使用
Run关键字If
和`Run关键字执行此操作的“旧方法”:

    FOR    ${line}    IN    @{lines}
        Run Keyword If    '${text}' == '${line}'    Run Keywords    Log    '${text} matched'
                                                       ...    AND   Exit For Loop
    END

我想知道Tidy是否会重新格式化
runkeywordif
调用新的
If
语法。那太好了。