如何测试网页上显示的数据与使用selenium ide的数据源(microsoft excel表)相同

时间:2012-04-09 15:15:48

标签: selenium-ide

我想测试一个网站,它以表格格式显示来自microsoft excel表格的所有数据,称为数据Feed。 任何人都可以帮我找到一个使用selenium ide的解决方案来测试网页上显示的数据是否与使用数据Feed中的一些独特列的数据Feed相同。

1 个答案:

答案 0 :(得分:0)

我使用Selenium IDE的DataDriven插件完成了这项工作。 (http://wiki.openqa.org/display/SEL/datadriven) 这个插件还需要Flow Control插件(也称为Sideflow) 和Include插件(Selenium IDE有一个单独的版本,请小心获取正确的版本)。

您需要做的一件事是将excel数据导出为插件所需的xml格式。我使用以下Excel宏来完成它:

    Sub MakeDataFile()

    Dim FileNo As Integer
    Dim CurrentLine As String
    Dim Filename As String
    Dim MyLoopIndex As Integer
    Dim NumRows As Integer
    Dim NumCols As Integer
    NumRows = ActiveSheet.UsedRange.Rows.Count
    NumCols = ActiveSheet.UsedRange.Columns.Count
    QT = Chr(34)
    Filename = "C:\YourFolder\YourDataFile.xml"
    FileNo = FreeFile
    Open Filename For Output As #FileNo
    ' write header to file
    Print #FileNo, "<testdata>"
    ' loop the sheet and write the data
    For MyRowIndex = 2 To NumRows
     OutputString = "<test "
     For MyColIndex = 1 To NumCols
      OutputString = OutputString & Cells(1, MyColIndex) & "=" & QT & Cells(MyRowIndex,        MyColIndex) & QT & " "
     Next MyColIndex
     OutputString = OutputString & " />"
     Print #FileNo, OutputString
    Next MyRowIndex

    ' write footer to file
    Print #FileNo, "</testdata>"
    Close #FileNo

    End Sub

我没有让宏足够聪明地处理小于字符,它想表达为:

&lt;

根据您的数据,可能还有其他特殊字符需要处理。 该脚本还假设电子表格包含字段名称作为第一行,并且电子表格的整个内容将成为要捕获的预期数据。