e-testing Blog

Extending HP UFT with Selenium Part 3

e-testing BlogIn the last article we looked at how to invoke the Selenium Server through HP UFT. Whilst this is all fine and well, there isn’t really much point unless we are using the features of UFT. In particular, object repositories.

This article will show how to use an object repository in Selenium.

In UFT, if we want to type cheese into the Google search box, our script might look like this:

Browser(“googleSearch”).Page(“homepage”).searchBox.set “cheese”

Each item in the object repository has methods allowing it to be read from or written to in this case set which then tells the browser driver to set the value of the object to “cheese” – once it has found it.

We are going to have to work out how the item in the repository is identified by the UFT browser driver and then pass this information on to the Selenium browser driver.

Each item in the repository has a method getTOProperty which we can use to find out how our item is being identified as well as retrieve the value. Here is a simple function which will we can use to know which item to choose:

function getObjectIdentifier(objElement, by, value)
Dim propertyValue: propertyValue = objElement.getTOProperty(“html id”)
if len(propertyValue) > 0 then by = “id”: value = propertyValue: exit function
propertyValue = objElement.getTOProperty(“xpath”)
if len(propertyValue) > 0 then by = “xpath”: value = propertyValue: exit function
propertyValue = objElement.getTOProperty(“name”)
if len(propertyValue) > 0 then by = “name”: value = propertyValue: exit function
propertyValue = objElement.getTOProperty(“css”)
if len(propertyValue) > 0 then by = “css”: value = propertyValue: exit function
end function

In the last article we retrieved the session id  from our local selenium host (http://localhost:4444/wd/hub) using the command:

objWebDriver.Open “POST”, “host/session”

objWebDriver.WaitForResponse

response = objWebDriver.responseText

sessionId = getJSONVALUE(response, “sessionId”)

Now we need to get the element id for the element we wish to set the value of:

objWebDriver.Open “POST”, “host/session/” & sessionId & “/element”, true

and we need to provide what we will be using to locate the element and the value and we will pass in the by and value which we got from our getObjectIdentifier function.

objWebDriver.send “{“”using””: “”” & by & “””, “”value””: “”” & value & “””}”

Now we need to tell the Selenium Server that we want to the text box to contain some text and we can do this using two commands:

clear to clear any existing text:

objWebDriver.Open “POST”, “host/session/sessionId/element/elementId/clear”, true

objWebDriver.send

and then value to provide the new text:

objWebDriver.Open “POST”, “host/session/sessionId/element/elementId/clear/value”, true

objWebDriver.send “{“”value””: [“”cheese””]}”

In this article, we looked at how to use our object repository with Selenium Server. If you would like to take things further,the source code and examples are available at github.

CLICK HERE FOR UPDATES

Subscribe to our RSS feed and get the latest updates in your inbox weekly

logo