使用selenium-on-rails的一些讨论 3]assertXpathCount的使用
3.assertXpathCount的使用
xpath_count一族的函数
assertXpathCount
storeXpathCount
...
会发现在selenium-on-rails中并没有对应函数assert_xpath_count等
原因是selenium-on-rails所用的selenium-core好像版本不够...没有assert_xpath_count
首先需要更新selenium-core,下载最新的,把core文件夹下的东西全部覆盖到selenium-core就可以
然后需要添加函数
分析doc,发现selenium-on-rails所有断言函数的原型是store_*,由此生成一族函数
For each store_foo there‘s assert_foo, assert_not_foo, verify_foo, verify_not_foo, wait_for_foo, wait_for_not_foo.
做出如下修改
一切OK
xpath_count一族的函数
assertXpathCount
storeXpathCount
...
会发现在selenium-on-rails中并没有对应函数assert_xpath_count等
原因是selenium-on-rails所用的selenium-core好像版本不够...没有assert_xpath_count
首先需要更新selenium-core,下载最新的,把core文件夹下的东西全部覆盖到selenium-core就可以
然后需要添加函数
分析doc,发现selenium-on-rails所有断言函数的原型是store_*,由此生成一族函数
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1
#selenium-on-rails/lib/selenium-on-rails/test_builder_accessors.rb
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
def store_xpath_count locator, variable_name
4
command 'storeXpathCount',locator, variable_name
5
end
6![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
def self.generate_methods
8
![](https://www.cnblogs.com/Images/dot.gif)
9
'store_whether_this_frame_match_frame_expression',
10
'store_whether_this_window_match_window_expression',
11
'store_xpath_count' ## tachikoma added
12
each_assertion method do |assertion_method, command_name|
13
![](https://www.cnblogs.com/Images/dot.gif)
14
end
generate_methods中第11行为添加项![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/dot.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/dot.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
一切OK