如何在Google页面中获得正确的排名搜索

时间:2014-05-09 03:47:14

标签: robotframework

我使用机器人框架(RF)搜索与我的网站相关的关键字,以了解/查找我的网站在Google搜索页面中的排名位置(排名:第1,第2,......)和哪个页面?第1页,第2页?)。

以下是我的代码:

*** Test Cases ***
Rank
    Open Browser    http://www.google.com.vn    gc
    Input Text      name=q                   atdd framework
    Submit Form     xpath=//form[@action='/search']
    Wait Until Element Is Visible       xpath=//div[@class='srg']/li[@class='g']
    ${xpa-count}=    Get Matching Xpath Count    xpath=//div[@class='srg']/li[@class='g']
    ${lis}=    Create List
    : FOR    ${i}    IN RANGE    1    ${xpa-count} + 1    # XPath indexes are 1-based, but Python is 0-based
    \    ${li}=    Get Text    xpath=//div[@class='srg']/li[@class='g'][${i}]
    \    Append To List    ${lis}    ${li}
    \    Log    ${li}
    Log List    ${lis}
    List Should Contain Value    ${lis}    robotframework.org/
    ${rank}=    Get Index From List    ${lis}    robotframework.org/
    ${rank}=    Evaluate    unicode(${rank} + 1)    # increment to get back to 1-based index
    Log     ${rank}
    Log    robotframework.org has rank ${rank}
    [Teardown]    Close All Browsers

但是,RF上的排名位置日志与Google屏幕不匹配:

Documentation:  
Logs the length and contents of the `list` using given `level`.
Start / End / Elapsed:  20140509 10:25:51.025 / 20140509 10:25:51.026 / 00:00:00.001
10:25:51.026    INFO    List length is 10 and it contains following items:
0: atdd-with-robot-framework - Google Code
code.google.com/p/atdd-with-robot-framework/ - Dịch trang này
This project is a demonstration on how to use Acceptance Test Driven Development (ATDD, a.k.a. Specification by Example) process with Robot Framework.
1: ATDDWithRobotFrameworkArticle - Google Code
code.google.com/.../robotframework/.../ATDDWithRobot...
Dịch trang này
21-11-2010 - Acceptance Test-Driven Development with Robot Framework article by Craig Larman ... See also ATDD With Robot Framework demo project.
2: tdd - ATDD versus BDD and the proper use of a framework ...
stackoverflow.com/.../atdd-versus-bdd-and-the-proper-us...
Dịch trang này
29-07-2010 - The Quick Answer. One very important point to bring up is that there are two flavors of Behavior Driven Development. The two flavors are xBehave ...
3: ATDD Using Robot Framework - SlideShare
www.slideshare.net/.../atdd-using-robot-framework
Dịch trang này
23-11-2011 - A brief introduction to Acceptance Test Driven Development and Robot Framework.
4: [PDF]
acceptance test-driven development with robot framework
wiki.robotframework.googlecode.com/.../ATDD_with_Ro...
Dịch trang này
WITH ROBOT FRAMEWORK by Craig Larman and Bas Vodde. Version 1.1. Acceptance test-driven development is an essential practice applied by suc-.
5: Robot Framework
robotframework.org/
Dịch trang này
Robot Framework is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD). It has easy-to-use tabular test ...
6: Robot Framework - Google Code
https://code.google.com/p/robotframework/
Dịch trang này
Robot Framework is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD). It has easy-to-use tabular test ...
7: Selenium 2 and Thucydides for ATDD | JavaWorld
www.javaworld.com/.../111018-thucydides-for-atdd.html
Dịch trang này
18-10-2011 - Find out how Thucydides extends and rethinks ATDD. ... In this article I introduce Thucydides, an open source ATDD framework built on top of ...
8: ATDD | Assert Selenium
assertselenium.com/category/atdd/
Dịch trang này
24-01-2013 - Thucydides In this article I introduce Thucydides, an open source ATDD framework built on top of Selenium 2. Introducing Thucydides ...
9: (ATDD) with Robot Framework - XP2011
xp2011.org/content.apthisId=180&contentId=179
Dịch trang này
Acceptance Test Driven Development (ATDD) with Robot Framework. Executable requirements neatly combine two important XP practices: user stories and ...

请看第6个位置是Stackoverflow,但谷歌排在第5位。

还有一个问题,如果我的网站在第一页中不存在,如何扩展我的测试用例,然后我会在下一页搜索,然后获取页面ID?

感谢。

1 个答案:

答案 0 :(得分:0)

页面上的结果在测试和视觉检查时可能会有所不同。第一步是使用seleneium Get Source关键字来转储页面的HTML。然后,您可以使用它来验证代码是否正常工作。

为了扩展您的测试用例,我首先要写一个名为&#34的关键字;得到结果"返回结果和排名。我会写另一个名为&#34的关键字;下一页"这将进入下一页的结果。然后我会写另一个名为&#34的关键字;找到带有结果&#34的页面;呼叫"得到结果"在一个循环中。在循环体中,我会调用"得到结果"。如果找不到结果,请拨打"下一页"然后再循环。最终,此关键字将找到包含结果的页面。