Wednesday 8 July 2015

Download Selenium jar from firefox Browser

This post objective is to illustrate how to use Selenium from Firefox Browser.
Java code snippet is here:
@Test

 public void testDownload() throws Exception {

  WebDriver driver = new FirefoxDriver(FirefoxDriverProfile());

  driver.manage().window().maximize();

  driver.get("http://seleniumhq.org");

  Thread.sleep(5000);

  driver.findElement(By.linkText("Download")).click();

  Thread.sleep(5000);

  driver.findElement(By.linkText("2.46.0")).click();

  Thread.sleep(5000);

 }


 public static FirefoxProfile FirefoxDriverProfile() {

  FirefoxProfile profile = new FirefoxProfile();

  profile.setPreference("browser.download.folderlist", 2);

  profile.setPreference("browser.download.manager.showWhenStarting",false);

  profile.setPreference("browser.download.dir", "E:\\sari\\os");

  profile.setPreference("browser.helperApps.neverAsk.openFile","text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/java-archive");

  profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/java-archive");

  profile.setPreference("browser.helperApps.alwaysAsk.force", false);

  profile.setPreference("browser.download.manager.alertOnEXEOpen", false);

  profile.setPreference("browser.download.manager.focusWhenStarting",false);

  profile.setPreference("browser.download.manager.useWindow", false);

  profile.setPreference("browser.download.manager.showAlertOnComplete",false);

  profile.setPreference("browser.download.manager.closeWhenDone", false);

  return profile;

 }





Monday 6 July 2015

How to read XML File from a Java program?

<?xml version="1.0" ?>
- <listofname>
- <emp id="1001">
  <firstname>saritha</firstname>
  <lastname>chary</lastname>
  <salary>10000</salary>
  </emp>
- <emp id="2001">
  <firstname>Babu</firstname>
  <lastname>BhayaRaj</lastname>
  <salary>1000000</salary>
  </emp>
  </listofname>




Java Program:



package SeleniumPrograms;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;

import java.io.File;

public class ReadforXmlfile {

public static void main(String[] args) throws Exception {
 
File fXmlFile = new File("E:\\sari\\os\\list.xml");//xml file path
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("emp");
System.out.println("_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode =nList.item(temp);
 
System.out.println("\nCurrent Element :" + nNode.getNodeName());//it will display current element node
 
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
 
Element eElement = (Element) nNode;
 
System.out.println("emp id : " + eElement.getAttribute("id"));
System.out.println("First Name : " + eElement.getElementsByTagName("firstname").item(0).getTextContent());
System.out.println("Last Name : " + eElement.getElementsByTagName("lastname").item(0).getTextContent());
System.out.println("Salary : " + eElement.getElementsByTagName("salary").item(0).getTextContent());
 
}
 }}
}
 


Saturday 4 July 2015

Download links for selenium

This post is created in the view of newbies for Selenium Automation and their system setup. In your system make a separate work directory and name it as Selenium-Works. Most of the Windows or Linux systems when you download files it will be stored in the Downloads directory.

Selenium automation Learning Path


These is the starting point of simply learn Selenium Automation. Know basic about Java programming or Python programming. If you know when to use what then it would be time saver and also your efforts.

Here we have URL's for Downloads select your favorite latest and stable versions.
  1. Eclipse used to develop the Java code http://www.eclipse.org/downloads/  --
  2. JDK is required to run the Java. http://www.oracle.com/technetwork/java/javase/downloads/index.html 
  3. Selenium-server-standalone jar file select latest stable version http://docs.seleniumhq.org/download/  --
  4. Firebug  https://addons.mozilla.org/en-US/firefox/adon/firebug/
  5. Firepath https://addons.mozilla.org/en-US/firefox/addon/firepath/ 
  6. ChromeDriver http://chromedriver.storage.googleapis.com/index.html
  7. IE Driver http://docs.seleniumhq.org/download/
  8. Sikuli https://launchpad.net/sikuli/+download  
  9. Bugzilla https://landfill.bugzilla.org/bugzilla-4.4-branch/

Will keep adding soon with latest new browser drivers, which are required in different projects. Most common browsers Mozilla, IE, Chrome related downloads given above. If you found any other driver related information please comment here.