In my last post I introduced Selenium, an open-source testing platform with an easy-to-use Firefox plugin that can be used as a cost-effective tool for regression testing web-based applications like OBIEE. I promised to demonstrate workaround to OBIEE-specific challenges when using Selenium, namely:
- Selenium's problematic handling of daughter or "target" windows, and
- Dynamic element ID generation in OBIEE
Here's a common scenario impacted by these challenges: When configuring a Dashboard to link to another Dashboard, OBIEE would open the new Dashboard in a "daughter" or "target" window.
Selenium would have trouble scripting this behavior because a) the only way Selenium can effectively identify target windows is by element ID (this is a known issue that doesn't appear to have a resolution from the Selenium project forthcoming anytime soon - though, in the grand tradition of Open Source software, you are welcome to figure out your own fix!) and b) OBIEE generates element ID's dynamically, which means they will change with each instance of the Presentation Server. So any Selenium-generated script would not work against a different Presentation Server, or against the same Presentation Server after a restart.
To illustrate the problem more clearly, I will create links to Dashboard pages in "My Dashboard." In this example I created links to "Brand Analysis", "Regional Analysis" and "Year over Year Analysis".
As you know, clicking into any of these links opens a new window (whose name = "_blank") to display the selected dashboard.
The workaround solution to this problem: 1) identify the URL that is opened in the "_blank" window, then 2) execute a standard Selenium "Open" command on that URL.
The key is the first step: identifying the URL of the "_blank" window. Doing so involves two tricks: a) Identifying the desired <A> element using XPath (which is an open standard that Selenium relies on to identify & interact with page elements); then b) identifying its HREF attribute.
If you're not familiar with XPath, it may be helpful to take a look at the following sites first, each of which offer a concise one-page explanation of XPath basics:
- XPath Syntax
http://www.w3schools.com/xpath/xpath_syntax.asp - How XPath Works
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPXSLT3.html
<a
href = "saw.dll?PortalPages[...]Done=Close"
target = "_blank"
name = "SectionElements">
<span
class="NavLinkCaption">
Brand Analysis
</span>
</a>
The "attributes" of the <a> tag (or "Element") are "href", "target" and "name". Their respective values are 'saw.dll?PortalPages[...]Done=Close', '_blank', and 'SectionElements'.
The "attribute" of the <span> element is "class" and its value is 'NavLinkCaption".
The "child" of the <a> element is the <span> element. Or put another way, the <a> element is the "parent" of the <span> element.
The <span> element content "contains" the text 'Brand Analysis'.
Using XPath there are several ways to identify an element, but not all can be used with web pages created in OBIEE:
- Element ID - Usually the best approach, and is the default behavior in Selenium, however this approach is not possible because OBIEE generates element ID's dynamically
- Ordered location in the document - Not advisable because any change in document content (e.g., adding a new <a> tag before the desired <a> tag) may break the XPath query
- Attribute (href, target, name, etc) - Not possible because OBIEE attributes are not unique; there are several href's whose target = "_blank" or name = "SectionElements"
- Displayed content - The best bet for OBIEE, since displayed content will be unique by definition (how else could the user differentiate between the links?)
//a/span[contains(.,'Brand Analysis')]
Pseudo-SQL translation: Select span.* from document where span.parent = <a> and span.content like '%Brand Analysis%'
Then the ".." expression (meaning "Parent of") can be used to identify the desired <a> tag, which is the parent of the <span> tag we identified above.
//a/span[contains(.,'Brand Analysis')]/..
Pseudo-SQL translation: Select span.parent from document where span.parent = <a> and span.content like '%Brand Analysis%'
Now we're going to use this XPath path expression to create two Selenium test case steps -- one which uses the Selenium saveAttribute command to assign the value of the <a> tag's href to a variable named 'windowURL', and another which opens that URL within the current window:
[Background: Selenium steps consist of three components: Command, Target and Value - For full documentation of Selenium's functionality see its official site: http://seleniumhq.org/docs]
Step 1:
Command: storeAttribute
Target: //a/span[contains(.,'Brand Analysis')]/..@href
Value: windowURL
Step 2:
Command: open
Target: ${windowURL}
Value: [blank]
Here's how the commands would look like in Selenium:
There are many more aspects to Selenium integration with OBIEE to learn that I hope to touch on in subsequent posts - but this little tutorial should give you a good start.
Have fun...
0 comments:
Post a Comment