How to verify image with watir script.

22 views
Skip to first unread message

srik

unread,
Jul 29, 2009, 12:24:11 PM7/29/09
to iTest2
Hi Zhimin,

Thanks for giving beneficial guidance.

1)how to verify the image present in table cell using watir script.

<td align="center" width="10%">
<a onclick="return listItemTask('cb6','publish')" href="javascript:
void(0);">
<img height="12" border="0" width="12" alt="" src="images/
publish_x.png"/>
</a>
</td>

2) If there any alternate solution (how to identify text area in IE
Explorer using watir script.)

browser.area(:id, "headerdesc").set("Public Asked to Choose World's
Seven Wonders")
(or)
browser.area(:id, "extra_info").set "#{extrainfo}"

3)how to verify the number present in table cell using watir script.

Thanks
Srikanth

Zhimin

unread,
Jul 29, 2009, 7:47:48 PM7/29/09
to iTest2
Srikanth,

> 1)how to verify the image present in table cell using watir script.

# veify an image in specifc table cell.
@browser.cell(:id, "surveyLabel").html.should include("/images/
main_window_200.png")

> 2) If there any alternate solution (how to identify text area in IE
> Explorer using watir script.)

@browser.text_field(:id, "comments").set("text in area")

> 3)how to verify the number present in table cell using watir script.

@browser.cell(:id, "surveyLabel").html.should include("/images/
main_window_200.png")

Here is a complete (ready to execute) test script

#----------------------
require 'watir'
require 'spec'

spec "iTest2 Demo using Watir - IE" do

before(:all) do
@browser = Watir::IE.start("http://itest2.com/demo/survey")
end

after(:all) do
@browser.close unless debugging?
end

test "table cell" do
@browser.cell(:id, "surveyId").text.should match(/\d+/) # match
integer
@browser.cell(:id, "surveyId").text.to_i.should == 101 # get
integer

# veify an image in specifc table cell.
@browser.cell(:id, "surveyLabel").html.should include("/images/
main_window_200.png")
end

test "area" do
@browser.text_field(:id, "comments").set("text in area")
end

end
#------------

Cheers,
Zhimin

srikanth gudikadi

unread,
Aug 3, 2009, 12:21:07 PM8/3/09
to ite...@googlegroups.com

Hi  zhimin,

Thanks for expensive suggestions.

Issue:

#1 I am using script like

browser.cell(:index,3).html.include? "images/tick.png"

and

browser.row(:index,3)[3].html.include? "images/publish_x.png"

I need to confirm the above scripts verify the image exists or not. Please suggest me if there any alternate way to handle the same with Watir.

Thanks,

Srikanth

Zhimin

unread,
Aug 3, 2009, 6:53:04 PM8/3/09
to iTest2
Srikanth,

Your two ways are fine, except if later there are new tables added to
the page, your test might fail. Generally I prefer to specific IDs if
can get developers to change the application.

Cheers,
Zhimin

On Aug 4, 2:21 am, srikanth gudikadi <sreekanth.gudik...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages