在 Watir-webdriver 中测试 svg 图表

Testing svg charts in Watir-webdriver

我正在尝试测试图表的标题是否正确 'Revenue'。我正在使用 watir-webdriver 来自动执行这些测试。

HTML代码:

<nvd3-multi-bar-chart data="chartData" id="revenueChart" class="chart-render ng-isolate-scope" showxaxis="true" showyaxis="true" color="colorFunction()" interactive="true" xaxistickformat="xAxisTickFormat()" yaxistickformat="yAxisTickFormat()" yaxisshowmaxmin="false" callback="chartCreatedCallbackFunction()" nodata="">
<text x="20" y="20" text-anchor="start" class="statistics-title">Revenue</text>
<text x="20" y="40" text-anchor="start" class="statistics-title-total">Total: 1,222,140 USD</text>

我能想到的就是这个:

if @browser.div(:xpath, '//*[@id="revenueChart"]/svg/text[1]').class == 'Revenue'
    print_green('Revenue Chart title           --- Pass')
end

据我了解,请尝试以下操作:

   if @browser.element(:xpath, '//*[@id="revenueChart"]/svg/text[0]').text == 'Revenue'
        print_green('Revenue Chart title --- Pass')
    end

这是一个使用 elementclass 定位器的非 xpath 替代方案:

if b.element(class: "statistics-title").text == "Revenue"
  # your message here
end