Selenium

Read a XML test data in Java 

Here is the code to read the xml test data coded in Java.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;

public class ReadXmlData {
public String value;

public String data(String node) {
try {
File file = new File("../TestData.xml"); // XML file path
FileInputStream fileInput = new FileInputStream(file);
Properties properties = new Properties();
properties.loadFromXML(fileInput);
fileInput.close();
Enumeration enuKeys = properties.keys();
while (enuKeys.hasMoreElements()) {
if (((String) enuKeys.nextElement()).contains(node)) {
value = properties.getProperty(node);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return value;
}
}

By Pavandeep Puddupakkam on July 22, 2013 | Java | A comment?
Tags: , , , ,

Using clickAt in Selenium Webdriver 

Here is the code to use clickAt in Selenium Webdriver

public void clickAt(By by) throws InterruptedException {
Thread.sleep(1500);
Actions builder = new Actions(driver);
WebElement tagElement = driver.findElement(by);
builder.moveToElement(tagElement).click().perform();
}

By Pavandeep Puddupakkam on October 25, 2012 | Java, WebDriver | A comment?
Tags: , , , ,

TFS Visual Studio 2010 and Excel Integration TF80070 error – Selenium Excel Test Data 

I am using Excel to store the test data and use Visual Studio 2010 C# to code the selenium scripts. When running the scripts I was getting the TF80070 error. I had to click on the confirmation box to continue testing. So it when from automation testing to manual testing (because of the error message).
Anyway here is the solution.
Open excel and then go to excel options. Select Add-Ins and the from the manage select list select COM Add-ins. From the COM Add-ins uncheck Team Foundation Add-in check box. This will stop the annoying error message from appearing.

Verifying the canonical tag on a web page using Selenium GetLocation 

Here is an example to verify the canonical tag on a web page using Selenium GetLocation. The selenium script is written in C#

public int CheckCanonicalTag()
{
int resultcount = 0;
string URL = selenium.GetLocation();
if (selenium.IsElementPresent("//link[@rel='canonical' and @href='" + System.Web.HttpUtility.UrlDecode(URL) + "']"))
{
Console.WriteLine( "Canonical tags is present on the page :" + URL);
}
else
{
Console.WriteLine( "Canonical tags is not present on the page :" + URL);
resultcount++;
}
return resultcount;
}

I have used System.Web.HttpUtility.UrlDecode because if I have to read the URL that has non English characters example Japanese the characters are encoded.

By Pavandeep Puddupakkam on November 17, 2011 | Selenium RC, Visual Studio 2010 | 1 comment
Tags: , , ,