Class: IEBrowserContext

Inherits:
Object
  • Object
show all
Includes:
Test::Unit::Assertions, Watir, Watir::Simple
Defined in:
lib/IEContext.rb

Overview

IEBrowserContext is an extension of Watir::Simple and is the core class through which all calls to Internet Explorer are made. IEBrowserContext should not be referred to directly within any WSL test scripts.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(testName = nil, logFile = nil) ⇒ IEBrowserContext

Initialises a new IEBrowserContext object. Essentially this is inherits from Watir.Simple, and uses it’s class variable #browser.

  • testName: The name you want to give the test.

  • logFile: The file you want to log to. Defaults to a log file with the same name as the script in the logs directory.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/IEContext.rb', line 26

def initialize(testName=nil, logFile=nil)
	# Set the test name.
	@testName = testName

	# Put the log file in the logs directory.
	if logFile == nil then
		logFile = $0.to_s.split("/")[-1].chomp(".rb") + ".log"
	end
	
	logFile = "logs/" + logFile
				
	# Create the logger.
	@logger = Wsl::CustomLogger.new(logFile)	

	# Output name if passed in.
	@logger.logTestName(testName) if testName != nil
end

Instance Attribute Details

#loggerObject (readonly)

Readonly access to logger.



16
17
18
# File 'lib/IEContext.rb', line 16

def logger
  @logger
end

#testNameObject

Returns the value of attribute testName.



15
16
17
# File 'lib/IEContext.rb', line 15

def testName
  @testName
end

Instance Method Details

#attach(windowTitle) ⇒ Object

Attaches to a titled browser window.

  • windowTitle: The titled window to attach to.



66
67
68
# File 'lib/IEContext.rb', line 66

def attach(windowTitle)
	@@browser = Watir::IE.attach(:title, windowTitle)
end

#browserObject

Provides access to the Watir::Simple::browser class variable.



58
59
60
# File 'lib/IEContext.rb', line 58

def browser
	return @@browser
end

#currentUrlObject

Returns the browser url.



47
48
49
50
51
52
53
# File 'lib/IEContext.rb', line 47

def currentUrl
	if defined? @@browser then
		return @@browser.url()
	else
	return ""
	end
end

#tagsInContextObject

The tags which are within scope of the browser context. First class functions make calls based on this.

Note: Ordering of the tags is important.

  • Returns an arraylist of string objects referring to the Watir::Simple tags that are within scope.



78
79
80
# File 'lib/IEContext.rb', line 78

def tagsInContext()
	%w[button link image div span text_field checkbox radio select_list]
end