Class: Page

Inherits:
Object
  • Object
show all
Defined in:
lib/core/PageObject.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser, pageobject) ⇒ Page

Returns a new instance of Page.



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/core/PageObject.rb', line 318

def initialize(browser, pageobject)
	@browser = browser
	@name = pageobject['page']['name']
	@url = pageobject['page']['url']
	@title = pageobject['page']['title']

	@elements = Hash.new

	if pageobject.key? 'elements'
		for object in pageobject['elements']
			element = Element.new(self, object)

			if @elements.key? element.name
				Log.Info "#{@name}\nDuplicate element name: '#{element.name}'"
			else
				@elements[element.name] = element
			end
		end
	end
end

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



316
317
318
# File 'lib/core/PageObject.rb', line 316

def browser
  @browser
end

#elementsObject

Returns the value of attribute elements.



316
317
318
# File 'lib/core/PageObject.rb', line 316

def elements
  @elements
end

#nameObject

Returns the value of attribute name.



316
317
318
# File 'lib/core/PageObject.rb', line 316

def name
  @name
end

#titleObject

Returns the value of attribute title.



316
317
318
# File 'lib/core/PageObject.rb', line 316

def title
  @title
end

#urlObject

Returns the value of attribute url.



316
317
318
# File 'lib/core/PageObject.rb', line 316

def url
  @url
end

Instance Method Details

#FindElement(name) ⇒ Object



349
350
351
352
353
354
355
356
# File 'lib/core/PageObject.rb', line 349

def FindElement(name)
	if @elements.key? name
		return @elements[name]
	end

	raise "Element not found in list: '#{name}'\n"
	return nil
end

#GoObject



339
340
341
342
343
344
345
346
347
# File 'lib/core/PageObject.rb', line 339

def Go()
	begin
		@browser.goto @url
	rescue Timeout::Error
		raise "Page load timeout\nURL: #{@url} (15 sec)\n"
	end

	return true
end

#VerifyTitleObject



358
359
360
361
362
363
364
365
366
367
# File 'lib/core/PageObject.rb', line 358

def VerifyTitle()
	@browser.windows.last.use

	if @title == @browser.title
		return true
	end

	Log.Failed("Title not matched", @browser.title, @title)
	return false
end

#VerifyURLObject



369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/core/PageObject.rb', line 369

def VerifyURL()
	@browser.windows.last.use

	uri = URI(@url)
	url = "#{uri.scheme}://#{uri.host}#{uri.path}"
	
	begin
		Watir::Wait.until(15) { browser.url.include? url }
		return true
	rescue
		Log.Failed("URL not matched", @browser.url, url)
		return false
	end
end