Ag-grid 使用 Robot Framework 实现自动化

Automation on Ag-grid using Robot Framework

我们有一个 UI 建立在 ag-grid 的基础上。在定位元素方面存在很多挑战,因为它没有 ID,而且 class 名称非常混乱。下面是一个例子。请建议我克服这些问题的方法,如果有任何材料或 link 请分享。提前致谢。

问题) 我想获取 'Income' header 以下的数据。以前,我曾处理过 rows/data 将是 'Income' header 的 child 元素的应用程序,但现在情况不同了。标签的位置与 'Income' header 无关(它们不是 'Income' 的 child 元素)。附件:显示Header及其下的数据

请建议我采用的方法。另外,这对我创建通用函数很有帮助。

因为网格是一个可预测的对象,所以它有结构,即使一开始并不明显。如果您希望为 ag-grid then I'd recommend porting their testing library functions found in ag-Grid Testing Utilities (100 lines) to Python. The library use is explained here: documentation.

创建一个通用函数

或者,您可以使用关键字将库作为一个整体加载:Get File followed by Execute Javascript 文件内容与您要在 JS 文件中执行的命令相连接。

但是,它似乎主要围绕这个获取定位器的函数展开:

getCssSelectorForRowAndCol = function (row, col, additionalSelector) {
   additionalSelector = additionalSelector || '';
   return "div[row-id=\"" + row + "\"] div[col-id=\"" + col + "\"] " + additionalSelector;
};

所以这应该允许您创建自定义函数,甚至是自定义定位器策略。举个简短​​的例子 SO answer.

编辑:以回答下面的问题为例:

*** Settings ***
Library    Selenium2Library

Test Setup        Start Browser
Test Teardown     Close Browser
Suite Teardown    Close All Browsers

*** Test Cases ***
Example Get Values
    ${cell_value_row_2}    Get Cell Value Test    name         2
    Log To Console    Cell value for Name in Row 2: [${cell_value_row_2}]

    ${cell_value_row_3}    Get Cell Value Test    mobile    3
    Log To Console    Cell value for mobile in Row 3: [${cell_value_row_3}]  

*** Keywords ***
Get Cell Value Test
    [Arguments]    ${colum_name}    ${row_number}=1
    ${get_Text}    Get Text    xpath=//div[@row-id="${row_number}"]/div[@col-id="${colum_name}"]
    [Return]    ${get_Text}

Start Browser
    Open Browser    https://www.ag-grid.com/example-runner/angular.php?section=angular-getting-started&example=rich-grid-example&fontawesome=1&bootstrap=1&enterprise=1&grid=%7B%22theme%22%3A%22ag-theme-fresh%22%2C%22height%22%3A%22100%25%22%2C%22width%22%3A%22100%25%22%2C%22enterprise%22%3A1%7D    Chrome
    Wait Until Element Is Visible    xpath=//div[@class="ag-body-container"]

应该在命令行中产生以下行:

Cell value for Name in Row 2: [Emily Braxton]
Cell value for mobile in Row 3: [+8710 846 6100 158]