Thursday, October 13, 2011

Data driven testing with Selenium

Data Driven Testing with Selenium:


Testing multiple data with same script.

the main intension of this testing is to find the behaviour 
of the application for different input values.

When i am executing my Test Cases which are same action up to some milestone. so I am are doing the same steps with different data... then I thought why should i do like this and i thought the data driven, how to do..first i thought for reusing the code.. then i created a class file then i am using the same class for all test cases in the class i am taking the values from xl file..

then i tried with java...then its working fine now..


package com.org.selected.datadriven;

import com.thoughtworks.selenium.*;
import java.io.File;
import java.sql.Time;
import java.util.regex.Pattern;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Blank;

import org.openqa.selenium.internal.seleniumemulation.Click;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


public class Datadriventest_firefox36 extends SeleneseTestCase {


Selenium selenium;
public static final String MAX_WAIT_TIME_IN_MS="30000";
private SeleniumServer seleniumServer;



@BeforeTest
public void setUp() throws Exception {

File template = new File("C:\\Documents and Settings\\username\\Application Data\\Mozilla\\Firefox\\Profiles\\Selenium");
RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.setFirefoxProfileTemplate(template);
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "URL");
seleniumServer.start();
selenium.start();
selenium.open("URL");
selenium.windowFocus();
selenium.windowMaximize();
}


@DataProvider(name = "Test")
// Test is hte xl file name, sheet1 is the sheet name and test1 is the table name.
public Object[][] createPayId() throws Exception{
    Object[][] retObjArr=getTableArray("D:\\workspace\\DemoProject\\datafiles\\Test.xls", "sheet1", "test1"); // what is these two ( sheet names )
    return(retObjArr);
}


@Test (dataProvider = "Test", description="Testing ")
public void Testpayments(String col1, String col2, String col3 )throws Exception {
selenium.setSpeed("500");
selenium.select("name=sn", xxx );
    pause(3000);
verifyTrue(selenium.isElementPresent("name=display"));
verifyTrue(selenium.isElementPresent("id=userid"));
verifyTrue(selenium.isElementPresent("name=rand_userid"));
selenium.select("name=aaa", col1);
selenium.select("name=livemode", col2);
selenium.type("id=amount", col3);
    selenium.click("id=Update");
pause(3000);

}

public String[][] getTableArray(String xlFilePath, String sheetName, String tableName) throws Exception{
    String[][] tabArray=null;
 
        Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
        Sheet sheet = workbook.getSheet(sheetName);
        int startRow,startCol, endRow, endCol,ci,cj;
        Cell tableStart=sheet.findCell(tableName);
        startRow=tableStart.getRow();
        startCol=tableStart.getColumn();


Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000,  false);              
        endRow=tableEnd.getRow();
        endCol=tableEnd.getColumn();
        System.out.println("startRow="+startRow+", endRow="+endRow+", " +
                "startCol="+startCol+", endCol="+endCol);
        tabArray=new String[endRow-startRow-1][endCol-startCol-1];
        ci=0;








Wednesday, October 12, 2011

Firefox profile for your Selenium RC

Why create a new firefox profile for Selenium?


We create firefox profile for Selenium RC tests, so we can set light configurations to it, which later on we’ll be using to run our Selenium scripts FASTER.

How to create Firefox profile for your Selenium?


1.Make sure all your firefox instance are closed
2.Click Start>Run
3.Type “firefox.exe -ProfileManager -no-remote”
4.Select “Create Profile” (i.e. selenium)
5.Click “Next”
6.Enter new profile name
7.Select a directory folder to store your new profile
8.Click “Finish”
9.Select “Don’t ask at startup”
10.Click “Start Firefox” and configure settings based on suggestion below***
11.Set Profile back to “default” (enable you to use your previous settings on your browser)
12.Add -firefoxProfileTemplate command line option as you start the Selenium Server

java -jar selenium-server.jar -firefoxProfileTemplate “

Suggested settings for your Selenium Profile


1.From “View\Toolbars” tab, uncheck “Bookmarks Toolbar”
2.Right click from toolbar and click “Customize”
3.Remove “Google search” by dragging it to the “Customize Toolbar” window
4.From the “Customize Toolbar” window, click “Use Small Icons” check box then hit “Done”
5.Click “Tools\Options” then set the following:
a. “Main” tab
- set Home Page to “about:blank”
- uncheck “Show the Downloads..” option
b. “Tabs” tab
- Select “a new window” for new pages
- Uncheck all warning options
c. “Content” tab
- uncheck “Block pop-up” windows option
d. “Privacy” tab
- uncheck all “History” options
e. “Security” tab
- uncheck all “Security” options
- click “Settings” and uncheck all warning options
f. “Advanced” tab
- Uncheck “autoscrolling” option from “General” tab
- uncheck “warn me …” and “Ssearch Engines”option from “Update” tab
6.From “Tools\Add-ons” install the following:
- Firebug: allows you to edit, debug, and monitor CSS, HTML, and JavaScript on your application under test
- Selenium IDE: allows you to record, edit, and debug Selenium tests
- ScreenGrab: saves entire webpages as images.
7.From the address bar type “about:config” and add the following by right-click anywhere on the page and selecting “new”
- extensions.update.notifyUser (type=boolean; value=false)
- extensions.newAddons (type=boolean; value=false)


Tuesday, September 6, 2011

StoreText in Selenium IDE



How user uses StoreText in Selenium IDE


When we want to reuse the data then we can use storetext command in SeleniumIDE.

It will store a value in a variable name then we can use that variable at any time in the same TestCase.

storeText(locator, variableName)

Here locator means location of an element, variableName means we have to declare the variableName.

then whenever we want to use same element then we can reuse that varialbe

Example
storeText(locator, variableName)

type(locator, variableName)

here we are storing the user name in the "ssss" variable
storeText(username, ssss)
here we are using "ssss" variable for enter username in the login page
type(formfield1, ${ssss})

Tuesday, August 16, 2011

how to export or take backup mysql database from command promprt in windows

find your mysql location where you installed

C:\Program Files\MySQL\MySQL Server 5.0>

then move to bin folder

C:\Program Files\MySQL\MySQL Server 5.0\bin>

then use this comand

mysql --user=root -proot testdb > export.sql

this will create export.sql file in the bin folder.

if you want to save backup file in the specific path then you give like that

mysql --user=root -proot testdb > d:\db_backup\export.sql

Wednesday, August 3, 2011

How to add 'Selenium IDE in firefox'



How to add 'Selenium IDE in firefox'

Open firefox ( firefox version should be morethan 3.5 v)
move to 'http://seleniumhq.org/download/'
download ide ( click on download version ) and click 'allow' for allowing popup.
restart firefox
move to 'Tools > Selenium IDE'

you can add selenium ide from this page also 'https://addons.mozilla.org/en-US/firefox/addon/flow-control/'

you can add selenium ide from  'Tools > Addons > get addon' > search for selenium and install then restart firefox

Run Selenese Directly Within the Server Using -htmlSuite

Run Selenese Directly Within the Server Using -htmlSuite

 You can run Selenese html files directly within the Selenium Server by passing the html file to the server’s command line. For instance:



java -jar selenium-server-standalone-.jar -htmlSuite "*firefox" "http://www.google.com" "c:\absolute\path\to\my\HTMLSuite.html" "c:\absolute\path\to\my\results.html"


This will automatically launch your HTML suite, run all the tests and save a nice HTML report with the results.


Installing TestNG on Eclipse

Installing TestNG on Eclipse
follow the simple steps below to install the TestNG plug-in on the eclipse IDE.

  • Open the Install/Update window from Help->Software Updates->Find and Install
  • Click on the radio button "Search for new feature to install" and click "Next" button
  • Click on the "New remote site..." and supply name as "TestNG" and URL as "http://beust.com/eclipse" and click on "OK"
  • Make sure the TestNG is checked and click on the "Finish" Button
  • Now follow the other steps and TestNG will be installed.