【问题标题】:Search an item in google using robotframework使用机器人框架在谷歌中搜索项目
【发布时间】:2018-05-06 18:41:02
【问题描述】:

我无法理解如何设置我的机器人框架的脚本以在 google 上进行简单搜索。

这是我的脚本:

*** Settings ***
Documentation                                      This is a basic test
Library                                            Selenium2Library

*** Variables ***
${url}                                              https://www.google.com
${browser}                                          chrome
${text}                                             xpath=//*[@id="lst-ib"]

*** Test Cases ***
User can open page
[Documentation]                                 As a user I can open the 
google page

open browser                                    ${URL}  ${BROWSER}
wait until page contains                        ${url}
close browser

User fill in the Search text box
[Documentation]                                 The user search 'Test 
Definition'

open browser                                    ${URL}  ${browser}
wait until page contains                        ${URL}
input text                                      ${text}  Test Definition
click button                                    btnK
wait until page contains                        Test

你能帮我在哪里出错吗?

【问题讨论】:

  • 运行此测试时会发生什么,它与您的预期有何不同?
  • 我有这个错误:WebDriverException:消息:未知错误:元素 在点 (516, 411) 不可点击。其他元素会收到点击:
    ...
    (Session info: chrome=62.0.3202.94) (Driver info: chromedriver=2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262),platform=Mac OS X 10.12.6 x86_64)
  • 错误告诉你有用的信息——输入框顶部有东西。

标签: google-chrome typescript testing automated-tests robotframework


【解决方案1】:

我将假设关键字之前缺少空格是无意的。对我来说,只有提交按钮没有使用正确的路径。所以,这是我更改并添加了close browser。下面的例子对我有用。

*** Settings ***
Documentation                                      This is a basic test
Library                                            Selenium2Library

*** Variables ***
${url}                                              https://www.google.com
${browser}                                          chrome
${text}                                             xpath=//*[@id="lst-ib"]
${search_button}                                    css=input.lsb

*** Test Cases ***
User can open page
    [Documentation]                                 As a user I can open the google page
    open browser                                    ${URL}    ${BROWSER}
    wait until page contains                        ${url}
    close browser

User fill in the Search text box
    [Documentation]                                 The user search 'Test Definition'
    open browser                                    ${URL}    ${browser}
    wait until page contains                        ${URL}
    input text                                      ${text}  Test Definition
    click element                                    ${search_button} 
    wait until page contains                        Test
    sleep     5s
    Close Browser

【讨论】:

    【解决方案2】:

    聚会可能迟到了,但我认为您的 xpath 不正确。像下面这样输入 css

    *** Variables ***
    | ${GoogleBaseUrl} | https://www.google.com/
    | ${GoogleForm} | css=form[name=f]
    | ${GoogleQuery} | css=input[name=q]
    
    *** KeyWords ***
    Open Google Search
        open browser  ${GoogleBaseUrl}    firefox  gl
        wait until element is visible  ${GoogleForm}
        wait until element is visible  ${GoogleQuery}
    

    那么你只需要确保你总是回到主页......

    Do Google Search
        [Arguments]  ${term}
        log to console  Do Google Search with "${term}"
        switch browser  gl
        go to  ${GoogleBaseUrl}
        wait until element is visible  ${GoogleForm}
        wait until element is visible  ${GoogleQuery}
        input text  ${GoogleQuery}  ${EMPTY}
        input text  ${GoogleQuery}   ${term}
        submit form
    

    【讨论】:

      【解决方案3】:

      一个简单的解决方案就是在 url 中添加一个查询参数。

      *** Settings ***
      
      Library     SeleniumLibrary
      
      *** Variables ***
      
      | ${GoogleForm} | css=form[name=f]
      | ${GoogleQuery} | css=input[name=q]
      | ${term}   | robotframework
      | ${GoogleBaseUrl} | https://www.google.com/search?q=${term}
      *** Test Cases ***
      This is sample test case
          [documentation]  Google test
          [tags]  regression
          Open Browser  ${GoogleBaseUrl}          chrome  ch
      
          Close Browser
      
      *** Keywords ***
      

      【讨论】:

        猜你喜欢
        • 2022-06-22
        • 2021-04-13
        • 2015-11-13
        • 2013-12-19
        • 1970-01-01
        • 2017-09-16
        • 1970-01-01
        • 2020-05-09
        • 2012-11-04
        相关资源
        最近更新 更多