机器人框架 - 区分大小写

时间:2013-06-12 15:01:12

标签: testing webdriver selenium-webdriver functional-testing robotframework

我需要知道是否有关于此错误的解决方法:

当我使用关键词时:

  • 位置应
  • 位置应包含
  • (这两者都是Selenium2Library的一部分。)

    我收到此错误: “位置应为”http://www.google.pt“,但为”http://WwW.GooGLe.Pt

    我认为这是因为在比较字符串时,机器人框架本身区分大小写。

    有任何帮助吗? TY

    修改 编辑问题以澄清一些主题。

    2 个答案:

    答案 0 :(得分:3)

    幸运的是Robot Framework允许用python编写关键字。

    MyLibrary.py

    def Compare_Ignore_Case(s1, s2):  
        if s1.lower() != s2.lower():
            return False
        else:
            return True
    
    def Convert_to_Lowercase(s1):
        return s1.lower()
    

    MySuite.txt

    | *Setting* | *Value*        |
    | Library   | ./MyLibrary.py |
    
    | *Test Case* | *Action* | *Argument*
    #
    | T100 | [Documentation] | Compare two strings ignoring case.
    |      | Compare Ignore Case | foo | FOO
    #
    | T101 | [Documentation] | Compare two strings where one is a variable.
                      # Should be Get Location in your case.
    |      | ${temp}= | MyKeyword that Returns a String
    |      | Compare Ignore Case | foo | ${temp}
    

    我没有使用Selenium库,但T101中的示例应该适合您。

    答案 1 :(得分:1)

    以防其他人想要这个:

    Location should be '${expectedUrl}' disregard case
        ${currUrl}    get location
        ${currUrl}    evaluate    "${currUrl}".lower()
        ${expectedUrl}    evaluate    "${expectedUrl}".lower()
        should be equal    ${currUrl}    ${expectedurl}
    
    Location should contain '${expected}' disregard case
        ${currUrl}    get location
        ${currUrl}    evaluate    "${currUrl}".lower()
        ${expected}    evaluate    "${expected}".lower()
        should contain    ${currUrl}    ${expected}