Top Level Namespace

Defined Under Namespace

Modules: Wsl Classes: IEBrowserContext

Instance Method Summary collapse

Instance Method Details

#assert_all_text(args) ⇒ Object

Asserts that all the text in the args array exists on screen.

Example usage -

assert_all_text ["value1", "value2", "value3"]
  • Returns true if all the text exists, false if at least one of values in doesn’t exist.



466
467
468
469
470
471
472
473
474
475
476
# File 'lib/wsl.rb', line 466

def assert_all_text(args)
	@myBrowser.logger.logExpectedResult("Asserting all text is shown on screen...")
		
	# Iterate and return false if any member of the array doesn't exist.
	args.each do |at|
		return false if !assert_text(at, "Expecting " + at + " to exist on screen.") 
	end
	
	# Otherwise assertion is true.
	return true
end

#assert_button_exists(what, expectedResult) ⇒ Object

Records a PASS if the button exists

  • what: The HTML id of the button

  • expectedResult: The expected result of this assertion

  • returns true if button exists on screen



623
624
625
626
627
628
629
630
631
632
633
# File 'lib/wsl.rb', line 623

def assert_button_exists(what, expectedResult)
	@myBrowser.logger.logExpectedResult(expectedResult)

	if @myBrowser.browser.button(:id, what).exists? then
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::pass, "Button does exist")	
		return true
	else
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::fail, "Button does not exist")
		return false
	end
end

Records a PASS if the link exists

  • what: The HTML id of the link

  • expectedResult: The expected result of this assertion

  • returns true if link exists on screen



604
605
606
607
608
609
610
611
612
613
614
# File 'lib/wsl.rb', line 604

def assert_link_exists(what, expectedResult)
	@myBrowser.logger.logExpectedResult(expectedResult)

	if @myBrowser.browser.link(:id, what).exists? then
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::pass, "Link does exist")	
		return true
	else
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::fail, "Link does not exist")
		return false
	end
end

#assert_text(text, expectedResult = nil, timeout = 60) ⇒ Object

Records expected result, then asserts whether the text is displayed on screen to verify the expected result. This keyword polls the browser for the specified amount of time until the text exists on screen. If the text doesn’t exist within the timeout period a fail is recorded.

Typical usage -

assert_text "Welcome Back", "Exists on screen for a successful login."

You can also use this within conditional statements within your test script. If you want to do so do not enter an expectedResult for brevities sake. Typical usage in a conditional statement -

if assert_text "Welcome Back" then 
  click "myMail"
else
  click "forgottenPwd"
end
  • text: The text to look for on screen.

  • expectedResult: The expected result we are trying to verify.

  • timeout: how long to try asserting for until we log a fail in seconds.



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/wsl.rb', line 389

def assert_text(text, expectedResult=nil, timeout=60)		
	@myBrowser.logger.logExpectedResult("'" + text + "' " + expectedResult) if expectedResult != nil
	isFound = check_for_text(text)
	
	# Until conditions met sleep for 1 sec and then try again.
	if timeout > 0 then 
		tries = 0
		
		until isFound || tries >= timeout do		# URL match found or timeout exceeded.
			isFound = check_for_text(text)
			sleep 1
			tries += 1
		end
	end
	
	if isFound then
		# Text found
		if expectedResult != nil then
			@myBrowser.logger.logActualResult(Wsl::CustomLogger::pass, "'" + text + "' found on screen.")
		end
		return true
	else
		# Text wasn't found
		if expectedResult != nil then
			@myBrowser.logger.logActualResult(Wsl::CustomLogger::fail, "'" + text + "' NOT found on screen.")
		end
		return false
	end
end

#assert_text!(text, expectedResult = nil) ⇒ Object

– Records expected result, then asserts whether the text is NOT displayed on screen to verify the expected result.

text: The text to look for on screen. expectedResult: The expected result we are trying to verify. - This could potentially be factored out??? ++ Do not use this is to be deprecated.



430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/wsl.rb', line 430

def assert_text!(text, expectedResult=nil)
	@myBrowser.logger.logExpectedResult("'" + text+ "' " + expectedResult) if expectedResult != nil 
		
	begin		
		if defined? @myBrowser.assert_text_in_body(text) then
			
			# If this is nil then we are doing a flow control assert - Do not log a test result
			if expectedResult != nil then
				@myBrowser.logger.logActualResult(Wsl::CustomLogger::fail, "'" + text + "' found on screen.")
			end
			
			return false
		else
			# If this is nil then we are doing a flow control assert - Do not log a test result
			if expectedResult != nil then
				@myBrowser.logger.logActualResult(Wsl::CustomLogger::pass, "'" + text + "' NOT found on screen.")
			end
			
			return true		
		end
	rescue => ex
		# Remember exception thrown when text not found.
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::pass, "'" + text + "' NOT found on screen.")
		return false
	end
end

#assert_url(url, expectedResult = "is current url.", timeout = 60, orFailValue = nil) ⇒ Object

Asserts that the current url matches the pased in url. If orFailValue is specified then a clever assertion is done whereby the method asserts every second until the url is matched, or the ‘orFailValue’ is matched to the url OR found in the text body. If neither of these conditions are met within the timeout period then a fail due to a time out is registered for this assertion.

The clever assertion is a workaround for any ajax submissions we do. currently there is no way to determine a response for an ajax call using Watir (There is an outstanding development request regarding this).

  • url: The url to match on.

  • expectedResult: The expected result message to show on screen.

  • timeout: period in seconds before registering a failed assertion.

  • orFailValue: a value if found in the url or body text registers a fail.



495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/wsl.rb', line 495

def assert_url(url, expectedResult="is current url.", timeout=60, orFailValue=nil)	
	# Get rid of the query string portion.
	splitUrl = @myBrowser.currentUrl.split("?")[0]
	
	@myBrowser.logger.logExpectedResult("'" + url.to_s + "' " + expectedResult.to_s)
	tries = 0
	
	begin
		# Clever assertion.
		if orFailValue != nil then	
			# Until conditions met sleep for 1 sec and then try again.
			until splitUrl.downcase  == url.downcase || 				# URL match found.
				splitUrl.downcase == orFailValue.downcase || 			# Fail value found in url.
				@myBrowser.assert_text_in_body(orFailValue) == nil ||	# Fail value found in body.
				tries >= timout do										# Timeout exceeded.
				sleep 1
				tries += 1
			end
		# Simple assertion.
		else
			# Until conditions met sleep for 1 sec and then try again.
			until splitUrl.downcase == url.downcase || 					# URL match found.
				tries >= timeout do										# Timeout exceeded.
				sleep 1													
				tries += 1
			end	
		end
				
		# Assert pass or fail.
		assert_url_conditions(splitUrl, url, timeout, orFailValue)
	rescue => ex
		@myBrowser.logger.logException ex
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::fail, 
			"'" + url.to_s + "' NOT current url or on screen." +
			"\n       '" + @myBrowser.currentUrl + "' is current url.")
		return false
	end		
end

#assert_url_conditions(currentUrl, url, timeout, orFailValue = nil) ⇒ Object

Called by assert_url.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wslPrivate.rb', line 9

def assert_url_conditions(currentUrl, url, timeout, orFailValue=nil)		
	# Pass: url matches
	if currentUrl.to_s.downcase == url.to_s.downcase
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::pass, "'" + 
			url + "' is current url.")
		return true
	# Fail: orFailValue found in url.
	elsif currentUrl.to_s.downcase == orFailValue.to_s.downcase then
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::fail, "'" + 
			url + "' is same as fail value: '" + orFailValue + "'")
		return false	
	# Fail: orFailValue found in body text.
	elsif orFailValue != nil && defined? @myBrowser.assert_text_in_body(orFailValue) then
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::fail, "'" + 
			orFailValue + "' found in body text.")
		return false	
	# Fail: timeout period expired.
	else
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::fail, 
		" Failed because of timeout (" + timeout.to_s + " secs).")
		return false			
	end	
end

#attach(windowTitle) ⇒ Object

Attaches the test to a new browser window – TODO: How to close the old window? ++

windowTitle: the name of the new window to attach to



50
51
52
53
# File 'lib/wsl.rb', line 50

def attach(windowTitle)
	@myBrowser.logger.logStep("Attaching to new window with title: '" + windowTitle + "'")
	@myBrowser.attach(windowTitle)
end

#backObject

Browses back a page.



81
82
83
84
# File 'lib/wsl.rb', line 81

def back
	@myBrowser.logger.logStep("Navigating back.")
	@myBrowser.browser.back()
end

#check_for_text(text) ⇒ Object

TODO: make this a closure.



34
35
36
37
38
39
40
# File 'lib/wslPrivate.rb', line 34

def check_for_text(text)
	begin		
		return @myBrowser.assert_text_in_body(text) == nil
	rescue => ex
		return false
	end
end

#cleanup_coreObject

These are core tasks that have to be performed AFTER any other startup tasks.



17
18
19
20
21
22
# File 'lib/utils/TestSuiteCleanup.rb', line 17

def cleanup_core
	# Print total summary at end of run.
	total_summary
	
	rem "Core cleanup activities completed."
end

#cleanup_script(*scripts) ⇒ Object

Declare the cleanup scripts here.

  • scripts: The cleanup scripts to load.



45
46
47
48
49
# File 'lib/wslSuite.rb', line 45

def cleanup_script(*scripts)
	scripts.each do |script|
		require script
	end
end

#clear_cacheObject

Clears the cache used by the logger.



116
117
118
119
120
121
122
123
# File 'lib/wsl.rb', line 116

def clear_cache
	if ! defined? @myBrowser then
		@myBrowser = IEBrowserContext.new()
	end
	
	# Clear the test cache so as not to corrupt the test summary.
	@myBrowser.logger.clearCache
end

#click(what, how = ":id") ⇒ Object

Clicks the HTML element with the id specified. Note if multiple elements are present it will click the first occurence of it only. The scope and order it searches in is viewable by calling elements_in_context.

  • what: the attribute value of the element we want to click

  • how: the attribute we want to use to uniquely identify the element



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/wsl.rb', line 250

def click(what, how=":id")
	@myBrowser.logger.logStep("Clicking on html element with #{how} '" + what + "'")
			
	# parse string to build up correct code with right 'how' attribute.
	code = <<TEMPLATE 
	@myBrowser.browser.send(tag, #{how}, what)
TEMPLATE
	
	@myBrowser.tagsInContext.each do |tag|
		# Evaluate the code to execute it.
		element = eval(code)  

		# Determine whether the passed in element id exists, and click it.
		if element.exist? && element.respond_to?(:click) then
			return element.click			
		end
	end 
	
	# Notify the user element was not find.
	@myBrowser.logger.log(" HTML element with #{how} '" + what + "' not found.")
end

#close(windowTitle = nil) ⇒ Object

Closes the attached browser window.

  • windowTitle: Closes the currently active browser window, unless the title of another browser window is specified.



60
61
62
63
64
65
66
# File 'lib/wsl.rb', line 60

def close(windowTitle=nil)
	# Attach to the browser with the name passed in.
	attach(windowTitle) if windowTitle != nil
	
	@myBrowser.logger.logStep("Closing browser")
	@myBrowser.close_browser
end

#current_urlObject

Returns the current url of the browser.



37
38
39
40
# File 'lib/wsl.rb', line 37

def current_url
	@myBrowser.logger.logStep("Current url: '" + @myBrowser.currentUrl + "'")	
	return @myBrowser.currentUrl
end

#elements_in_contextObject

Shows all the elements in context in the order they are searched through. Essentially this is showing use the scope of certain keywords such as click, select, etc.



684
685
686
687
# File 'lib/wsl.rb', line 684

def elements_in_context
	rem "elements in context in order of precedence: \n[" + 
		@myBrowser.tagsInContext().join(", ") + "]"
end

#enter_text_in(what, how = ":id", value = nil) ⇒ Object

end ++



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/wsl.rb', line 138

def enter_text_in(what, how=":id", value=nil)
	@myBrowser.logger.logStep("Entering text into html element with #{how} '" + what + "'")
	
	# parse string to build up correct code with right 'how' attribute.
	code = <<TEMPLATE 
	@myBrowser.browser.send(tag, #{how}, what)
TEMPLATE
	
	@myBrowser.tagsInContext.each do |tag|
		# Evaluate the code to execute it.
		element = eval(code)  
			
		# Determine whether the passed in element has the method we want.
		if element.exist? && element.respond_to?(:set) then
			begin
				return element.set(value)				
			rescue => ex	
				# Do nothing, we want to carry on through the list as 
				# more than one type of element may have the set method.
			end
		end
	end 
	
	# Notify the user element was not find.
	@myBrowser.logger.log(" HTML element with #{how} '" + what + "' not found.")
end

#finishObject

Finishes the test.



89
90
91
92
93
94
95
96
# File 'lib/wsl.rb', line 89

def	finish
	@myBrowser.close_browser		
	@myBrowser.logger.logEndTest
	@myBrowser.logger.summary
	
	# Reset step counter.
	@myBrowser.logger.reset
end

#go_to(url) ⇒ Object

Navigates to the given url.

  • url: the url to navigate to.



73
74
75
76
# File 'lib/wsl.rb', line 73

def go_to(url)
	@myBrowser.logger.logStep("Navigating to url: '" + url + "'")
	@myBrowser.browser.goto(url)
end

#IEContextObject

This file contains the core WSL keywords that are used to write test scripts. Refer to wsl.xqoob.com for examples on how to use these.



6
# File 'lib/wsl.rb', line 6

require "IEContext"

#key_press_in(field) ⇒ Object

Fires a javascript onKeyPress event for the given textbox.

  • field: The textbox to fire the event for (HTML id).



170
171
172
173
# File 'lib/wsl.rb', line 170

def key_press_in(field)
	@myBrowser.logger.logStep("Firing onKeyPress event for: '" + field + "'")
	@myBrowser.browser.text_field(:id, field).fire_event('onkeypress') 
end

#key_up_in(field) ⇒ Object

Fires a javascript onKeyUp event for the given textbox.

  • field: The textbox to fire the event for (HTML id).



180
181
182
183
# File 'lib/wsl.rb', line 180

def key_up_in(field)
	@myBrowser.logger.logStep("Firing onKeyPress event for: '" + field + "'")
	@myBrowser.browser.text_field(:id, field).fire_event('onkeyup') 
end

#manual_test(*steps) ⇒ Object

A manual test is a fall back strategy when it is difficult to write automated step(s). For example you may have to interact with an external site as part of your script to click on an email link, or when registering enter a captcha code.

manual_test is a workaround for such tricky scenarios. Essentially you list some steps to perform within the manual_test then record whether it is a pass or a fail. Note that irrespective of how many manual tests you have you can only record one pass or fail for all steps within it.

Example usage -

some automated steps
...
rem "Register on the site"
...
manual_test "enter the captcha"
click "submitBtn"
manual_test "submit registration",
            "login into email account",
            "click on registration email link"	
...
  • steps: The steps to perform within the manual test. Textual values comma separated for each step.



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/wsl.rb', line 571

def manual_test(*steps)
	@myBrowser.logger.log(" Manual steps to perform:")
	
	# Log the steps
	steps.each do |step| 
		@myBrowser.logger.logStep(step)
	end
	
	# Ask for pass or fail
	result = ""
	
	until result.upcase  == "P" || result.upcase == "F" do
		puts " Manual test pass or fail (P/F)? " 
		result = gets.chomp	
	end
	
	# Log result
	@myBrowser.logger.logExpectedResult("Manual test passes")
	
	if result.upcase == "P" then
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::pass, "Manual test passed")
	else
		@myBrowser.logger.logActualResult(Wsl::CustomLogger::fail, "Manual test failed")	
	end
end

#mouse_down(field) ⇒ Object

Fires a javascript onMouseDown event for the given textbox.

  • field: The textbox to fire the event for (HTML id).



200
201
202
203
# File 'lib/wsl.rb', line 200

def mouse_down(field)
	@myBrowser.logger.logStep("Firing onMouseDown event for: '" + field + "'")
	@myBrowser.browser.text_field(:id, field).fire_event('onMouseDown') 
end

#mouse_over(field) ⇒ Object

Fires a javascript onMouseOver event for the given textbox.

  • field: The textbox to fire the event for (HTML id).



190
191
192
193
# File 'lib/wsl.rb', line 190

def mouse_over(field)
	@myBrowser.logger.logStep("Firing onMouseOver event for: '" + field + "'")
	@myBrowser.browser.text_field(:id, field).fire_event('onMouseOver') 
end

#open_url(url) ⇒ Object

Opens a new browser with the given url.

  • url: The url to point the browser to.



26
27
28
29
30
31
32
# File 'lib/wsl.rb', line 26

def open_url(url)
	@myBrowser.logger.logStep("Opening browser at url: '" + url + "'")
		
	# Point to url and open.
	@myBrowser.new_browser_at(url)
	@myBrowser.browser.speed = :zippy
end

#rem(text) ⇒ Object

Logs a comment.

  • text: The comment to log.



539
540
541
# File 'lib/wsl.rb', line 539

def rem(text)
	@myBrowser.logger.logComment(text)
end

#retryable_steps(&block) ⇒ Object

Allows other steps to be executed and if certain conditions are not met then the steps are repeated. Ideal for performing some manual steps which if not done correctly then need to be repeated. If in the passed in block of steps conditions are not met then call retryable_steps_error with appropriate message to prompt for a repeat.

Example usage:

retryable_steps{
  Do some steps here
...
if pass condition is fail then

Do any further steps if needed … # Record the error with message retryable_steps_error “The steps failed you need to retry again”

   end
}
  • &block: The block of code to pass in (must be surrounded by ‘and ‘’)



656
657
658
659
660
661
662
663
664
665
# File 'lib/wsl.rb', line 656

def retryable_steps(&block)
	begin
		# Call the block
		yield
	rescue => ex 
		# Output the message for completeness and then retry.
		rem ex.message
		retry
	end
end

#retryable_steps_error(message) ⇒ Object

Used to report a retryable_steps needs to be re-tried. If in the retryable steps the condition(s) to determine pass/fail of the steps fails then call this.

  • message: The message to display before retrying.

Raises:

  • (ArgumentError)


674
675
676
677
# File 'lib/wsl.rb', line 674

def retryable_steps_error(message)
	# TODO: Create a custom error/exception?
	raise ArgumentError, message
end

#select(what, how = ":id", value = true) ⇒ Object

Selects the named element ideally should be used with checkboxes, radio buttons and dropdown lists. When set to true will select the checkbox or radio button. When selecting a value from a dropdown list it uses the passed in value.

  • what: the attribute value of the element we want to click

  • how: the attribute we want to use to uniquely identify the element

  • value: defaults to true, otherwise the value of the dropdown list.



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/wsl.rb', line 215

def select(what, how=":id", value=true)
	@myBrowser.logger.logStep("Selecting html element with #{how} '" + what + "'")
	
	# parse string to build up correct code with right 'how' attribute.
	code = <<TEMPLATE 
	@myBrowser.browser.send(tag, #{how}, what)
TEMPLATE
	
	@myBrowser.tagsInContext.each do |tag|
		# Evaluate the code to execute it.
		element = eval(code)  
			
		# Determine whether the passed in element has the method we want.
		if element.exist? && element.respond_to?(:set) then
			begin
				return element.set(value)				
			rescue => ex	
				# Do nothing, we want to carry on through the list as 
				# more than one type of element may have the set method.
			end
		end
	end 
	
	# Notify the user element was not find.
	@myBrowser.logger.log(" HTML element with #{how} '" + what + "' not found.")
end

#start(testName, logFile = nil) ⇒ Object

Starts the test. All test scripts should have this as the first statement.

  • testName: the name of the test.

  • logFile: the file to log to.



17
18
19
# File 'lib/wsl.rb', line 17

def start(testName, logFile=nil)
	@myBrowser = IEBrowserContext.new(testName, logFile)
end

#startup_coreObject

These are core tasks that have to be performed BEFORE any other startup tasks.



18
19
20
21
22
23
24
25
26
27
# File 'lib/utils/TestSuiteStartup.rb', line 18

def startup_core
	# Clear the cache of any old data.
	clear_cache

	# Workout the test suite name and initialise a suite logger.
	logFile = "logs/" + $0.to_s.split("/")[-1].chomp(".rb") + ".log"
	Wsl::CustomLogger.initializeSuiteLogger(logFile)
	
	rem "Core startup activities completed."
end

#startup_script(*scripts) ⇒ Object

Declare the startup scripts here.

  • scripts: The startup scripts to load.



23
24
25
26
27
# File 'lib/wslSuite.rb', line 23

def startup_script(*scripts)
	scripts.each do |script|
		require script
	end
end

#test_suite(*tests) ⇒ Object

Declare the test suite here.

  • tests: The tests to load and execute.



34
35
36
37
38
# File 'lib/wslSuite.rb', line 34

def test_suite(*tests)
	tests.each do |test|
		require test
	end
end

#total_summaryObject

Prints the total summary of all passed and failed tests in run.



102
103
104
105
106
107
108
109
110
111
# File 'lib/wsl.rb', line 102

def total_summary
	if ! defined? @myBrowser then
		@myBrowser = IEBrowserContext.new()
	end
	
	@myBrowser.logger.totalSummary
	
	# Clear the test cache so as not to corrupt the test summary.
	@myBrowser.logger.clearCache
end

#wait(aMoment = 0) ⇒ Object

Waits for the browser to catch up. Useful for ajax calls where the browser loads up some javascript.

  • aMoment: How long to wait for in seconds.



315
316
317
318
319
320
321
322
323
324
# File 'lib/wsl.rb', line 315

def wait(aMoment=0)
	if aMoment == 0 then
		@myBrowser.logger.logStep("Waiting  for browser to catch up")
	else
		@myBrowser.logger.logStep("Pausing for " + aMoment.to_s + " secs then waiting  for browser to catch up")
		sleep aMoment
	end
	
	@myBrowser.browser.wait
end

#wait_for(what, how = ":id", timeout = 60) ⇒ Object

Waits for the HTML element to exist on screen. Note if multiple elements are present it will look for the first occurence of it only or until the timeout (in seconds) is exceeded.

The scope and order it searches in is viewable by calling elements in context.

  • what: the attribute value of the element we want to click

  • how: the attribute we want to use to uniquely identify the element

  • timout: maximum amount of time to wait for (default is 60 secs).



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/wsl.rb', line 283

def wait_for(what, how=":id", timeout=60)
	@myBrowser.logger.logStep("Waiting to load: '" + what + "'")		 		
	tries = 0
	
	# parse string to build up correct code with right 'how' attribute.
	code = <<TEMPLATE 
	@myBrowser.browser.send(tag, #{how}, what)
TEMPLATE
	
	# Until timeout is exceeded (or element exists).
	until tries >= timeout do	
		@myBrowser.tagsInContext.each do |tag|
			element = eval(code)
			# Evaluate the code to execute it and see if it exists.	
			return if element.exists?	
		end
		
		# Sleep for a bit and then try again.		
		sleep 0.1
		tries += 0.1
	end
		
	# if got to here then notify the user element was not find.
	@myBrowser.logger.log(" HTML element with id '" + what + "' not found.")
end

#wait_until_visible(what, how = ":id", timeout = 60) ⇒ Object

Waits for the element to become visible or until the timeout period has elapsed.

  • what: the attribute value of the element we want to click

  • how: the attribute we want to use to uniquely identify the element

  • timout: maximum amount of time to wait for (default is 60 secs).

– TODO: Merge with wait_for method (add visible? to if condition) ++



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/wsl.rb', line 338

def wait_until_visible(what, how=":id", timeout=60)
	@myBrowser.logger.logStep("Waiting for : '" + what + "' to become visible")	
	
	tries = 0
	
	# parse string to build up correct code with right 'how' attribute.
	code = <<TEMPLATE 
	@myBrowser.browser.send(tag, #{how}, what)
TEMPLATE
	
	# Until timeout is exceeded (or element exists).
	until tries >= timeout do	
		@myBrowser.tagsInContext.each do |tag|
			# Evaluate the code to execute it and see if it exists.	
			element = eval(code)
			
			# Element exists and is visible.
			return element.visible? if element.exist? && element.visible?
		end
		
		# Sleep for a bit and then try again.		
		sleep 0.1
		tries += 0.1
	end
		
	# if got to here then notify the user element was not find.
	@myBrowser.logger.log(" HTML element with id '" + what + "' has not become visible before timeout.")	
end