Posts

Showing posts from 2014

Uploading Bulk data into MySql database using Java

Image
Let us see how can we upload / insert bulk data into MySql database from an excel So that we have data ready in excel . Let's see the java program to connect and upload data. We'll split our requirement into following sub tasks: 1. Connection to My Sql database. 2. Read the Excel using Apache POI. 3. Insert the data,by iterating row by row in the excel. 4.Close the database connection. Here's how it is implemented: package sample; import java.io.FileInputStream; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.Iterator; import org.apache.poi.ss.formula.functions.Column; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public cl

To Find out whether a number is Armstrong number

  Armstrong number  is a number that is the sum of its own digits each raised to the power of the number of digits. Let us Look at how to find out whether the number is Armstrong using java. Note: The input is saved in Text file. Input: 7 181 153 Output: True False True import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.File; public class Armstrong {     public static void main (String[] args)  throws FileNotFoundException,NumberFormatException{          File file = new File(args[0]);     BufferedReader in = new BufferedReader(new FileReader(file));    int len;    String currentline;                                 double num;                                 int y;                                 int sum = 0;                                 char z;    try     {          while ((currentline = in.readLine()) != null)        {  

Using ReportNg with Selenium WebDriver

Image
ReportNG is a simple HTML reporting plug-in for the  TestNG .  Why ReportNG? The ReportNG implementation maps each test class to a single <testsuite> element, resulting in one XML file per test class. This is different from the approach taken by the core TestNG implementation. What we need? To Start working with ReportNG , we need to download reportng-1.1.4 and velocity-dep-1.1.4 jar files which are latest versions till date. What Next? Add the above mentioned libraries to your Selenium +TestNg Project's build path. We need create testng.xml file which looks like <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite" parallel="none">  <listeners>      <listener class-name="org.uncommons.reportng.HTMLReporter"/>  </listeners>   <test name="SmokeTest">       <clas

Python in Eclipse

Image
Let us see how to set up Python in Eclipse IDE. Prerequisites :  Eclipse IDE  Python installed in your machine if not check this   link .  PyDev is a Python Development Environment (Python IDE plugin for Eclipse). Install PyDev via the Eclipse update manager . Refer :  http://pydev.org/updates or http://update-production-pydev.s3.amazonaws.com/pydev/updates/site.xml Launch Eclipse.Go to Help->Install New Software Click on Add. Enter any repository name and  the location as the link which mentioned above. Once you Add this. You will the repository added in the list of available software . Select the First check box “Py Dev” . Once this is done. Configure  Eclipse the location of your Python installation. Go to  Window → Preference →Pydev → Interpreters ->Python Interpreter menu. Click New.Enter Interpreter name and the Executable which is the location of the python. You are good to start coding in Python us

Selenium WebDriver: Working with a AutoSuggest box

Image
In this blog post , let us see how Mr.Web Driver is going to handle an Auto Suggest box . First and foremost point to be noted  is when you type a character(or) text  in the auto suggest box.we need to wait till application shows up some suggestions starting (or) containing the typed character. In the below illustrated example , Mr.Web Driver gives us an option to wait(using Explicit wait) until the suggestions are visible. public class Suggestbox { WebDriver driver=new FirefoxDriver();   @Test   public void cool() throws InterruptedException {  driver.get("http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwSuggestBox");  driver.manage().window().maximize();  WebDriverWait wait=new WebDriverWait(driver,10);  wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("gwt-debug-cwSuggestBox")));  //ENTER SOME VALUE IN SUGGEST BOX  driver.findElement(By.id("gwt-debug-cwSuggestB

Selenium WebDriver-Working with Listbox and Multi-Select Listbox

Image
We are going to see how to retrieve values of Single Select List box and How to Select multiple options in different ways on a Multi Select Listbox. import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; import org.testng.annotations.Test; public class Listboxes { WebDriver driver=new FirefoxDriver();   @Test   public void Listboxtest() throws InterruptedException {  driver.get("http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwListBox");  driver.manage().window().maximize();  Thread.sleep(5000); //1. Single select list box -->first value will be the default value of the dropbox  WebElement lbox=driver.findElement(By.id("gwt-debug-cwListBox-dropBox"));  List<WebElement>