watir and ajax tables
来源:互联网 发布:linux home代表什么 编辑:程序博客网 时间:2024/05/16 18:45
watir and ajax tables
I use watir a lot. I find that it’s easy to build a watir script, due to the simplicity of the language and versatility of the code. Even though my main role is to performance test a system for my client, watir scripts help me in my role, when I’m doing web testing.
This article is just to embed this process in my memory, or so I can refer to it in future, as well as possibly helping the wider community having trouble with watir and Ajax…
Currently, the application I’m testing has a lot of Ajax controls. With our Ajax controls, once you type the value you want to input, an drop down list appears, however this is not a list, it is a table.
You must then select the value you would like, even if you have entered the correct “string” and only one cell is returned..seems silly.
This is how I used to do it before
def workspace; @browser.frame(:name, "WORK_SPACE"); endbegin workspace.text_field(:name, "nameOfTextField").set("Restaurants") wait_until { workspace.cell(:title, "Restaurants").exists? } workspace.cell(:title, "Restaurants").clickend
..And it works well. However, I found some problems when my environment went down, and I had to work in a new/different environment. Sometimes the data was a little different, I wanted my watir script to be robust, in any environment. Changing hardcoded values is a pain, and paramtising the watir script seemed a little overkill for a script I only used when I needed to re-record a new script or setup some data.
The solution, well, there’s really two solutions. Either, not input any data at all and use the Ajax drop down menu, or input the first few letters of the data and select the first option in the drop down menu.
Instead of checking if “Restaurant” exists, after I’ve typed it in, I just decided to select the first cell that of the table was returned by the Ajax control.
It’s even proven to be useful for those text fields that has changing values, or where you don’t care what you enter, just as long as it has a value populated.
Here is the quick solution.
def workspace; @browser.frame(:name, "WORK_SPACE"); endbegin workspace.text_field(:name, "nameOfTextField").set("Restaurants") workspace.link(:id,"AjaxDropDownButton").click wait_until { workspace.table(:id,"EntireAjaxTableThatIsReturned").exists? } workspace.table(:id,"EntireAjaxTableThatIsReturned")[2][1].clickend
I select row 2, column 1 in the entire Ajax table that is returned as the row 1 column 1, is the heading of the table, the second row is the value I want selected.
This may be a bit of a no brainer, but its these little slight enhancements that make the script just that little more robust.
Obviously you don’t need this line :
workspace.text_field(:name, "nameOfTextField").set("Restaurants")
If you want to select the first value, or whatever row/column number you want.
Enjoy!
- watir and ajax tables
- watir
- Pooled and Cluster Tables
- Create Tables and Constraints
- Pooled and Cluster Tables
- Tables, Matrices, and Lists
- Temporary Tables and Table Variable
- Objects: Tables, Views and others
- Objects: Tables, Views and others
- Objects: Tables, Views and others
- SD Process Flow and tables
- 18 Partitioned Tables and Indexes
- AWE Tables and Migration script
- 图解iptables:chains and tables
- AWE Tables and Migration script
- About Compress Tables and structure
- System catalog tables and views
- Stock Tables and Stock Types
- 图的遍历算法DFS和BFS(C++)
- java 序列化,持久化(概念)
- 负数归零
- 获取Windows默认打印机名
- 人生的决定
- watir and ajax tables
- 我为何而生
- 求一个字符串中包含的对称子字符串的最大长度(两种方案,一个时间复杂度n2,一个时间复杂度n3)
- 第二节课堂感受
- 编写高质量C#代码(5)
- Andorid 内存泄露与 Eclipse Memory Analyzer
- Unity3D 游戏引擎之FBX模型的载入与人物行走动画的播放(十二)
- android 单元测试Test run failed: Test run failed to complete. Expected 1 tests, received 0
- c# 读数据库利用模板书签写word文件