Tuesday, October 18, 2011

Separate Firefox profile with SeleniumRC


package com.sample;


import com.thoughtworks.selenium.*;


import java.io.File;
import java.util.regex.Pattern;


import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;


public class Test67 extends SeleneseTestCase {
public Selenium selenium;
public Selenium settingup()throws Exception {
File template = new File("C:\\Documents and Settings\\sasidhar\\Application Data\\Mozilla\\Firefox\\Profiles\\Selenium");
RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.setFirefoxProfileTemplate(template);
SeleniumServer seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://google.com/");
seleniumServer.start();
selenium.start();
selenium.open("https://google.com");
selenium.windowFocus();
selenium.windowMaximize();
return selenium;
}

public void testUntitled() throws Exception {
selenium.open("about:home");
selenium.type("id=searchText", "sasidhar");
selenium.click("id=searchSubmit");
selenium.waitForPageToLoad("30000");
}
}

Friday, October 14, 2011

Webdriver - Drag And Drop

package script;
import org.openqa.selenium.By;
import org.openqa.selenium.RenderedWebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.selenium.SeleneseTestCase;

public class DragAndDrop extends SeleneseTestCase{
    public static void main (String[] arg)
    {
        WebDriver driver = new FirefoxDriver();
        WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, "http://www.webreference.com/programming/javascript/mk/column2/");
        driver.get("http://www.webreference.com/programming/javascript/mk/column2/");
        selenium.windowFocus();
        selenium.windowMaximize();
        RenderedWebElement from = (RenderedWebElement) driver.findElement(By.xpath("html/body/div[5]/div[2]/fieldset[1]/div/div[1]/div[1]"));
        RenderedWebElement to = (RenderedWebElement) driver.findElement(By.xpath("html/body/div[5]/div[2]/fieldset[1]/div/div[1]/div[2]"));
        from.dragAndDropOn(to);
        }
}

Web Driver - Handling Multiple Windows

package script;
import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;


public class HandlingWindows  {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, "http://www.way2sms.com/");
        driver.get("http://www.way2sms.com/");
        selenium.windowFocus();
        selenium.windowMaximize();
        driver.findElement(By.xpath(".//*[@id='header']/div/div/div[2]/a")).click();
        selenium.waitForPageToLoad("30000");
        System.out.println("Page title is: " + driver.getTitle());
        driver.findElement(By.id("username")).click();
        Set allWindowHandles = driver.getWindowHandles();
        String window0 = (String) allWindowHandles.toArray()[0];
        System.out.println("Window0 String: "+ window0);
        driver.switchTo().window(window0);
        String win0Title = selenium.getTitle();
        System.out.println("Window0 Title: "+ win0Title);
        String window1 = (String) allWindowHandles.toArray()[1];
        System.out.println("Window1 String: "+ window1);
        driver.switchTo().window(window1);
        String win1Title = selenium.getTitle();
        System.out.println("Window1 Title: "+ win1Title);     
     }
  }

Thursday, October 13, 2011

DataProvider in Selenium

f

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.

Monday, May 30, 2011

How To start Selenium



Follow the below steps:

1. Recode your steps in Selenium IDE

2. Have to convert to java code and paste in the eclipse

3. change the class name like sasidhar and save as sasidhar.java.

4. Start the selenium server

5. Execute your script in sclipse.
================================================
package com.example.tests;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;

public class sasidhar extends SeleneseTestCase {
    public void setUp() throws Exception {
        setUp("http://www.google.com/", "*firefox");
    }
      public void testNew() throws Exception {
          selenium.open("/");
          selenium.type("q", "selenium rc");
          selenium.click("btnG");
          selenium.waitForPageToLoad("30000");
          assertTrue(selenium.isTextPresent("Results * for selenium rc"));
    }
}
============================================

Thursday, March 10, 2011

MYSQL

How do you start and stop MySQL on Windows?  - net start MySQL, net stop MySQL


What’s the default port for MySQL Server? - 3306


What does tee command do in MySQL? - tee followed by a filename turns on MySQL logging to a specified file. It can be stopped by command notee.


Use mysqldump to create a copy of the database? - mysqldump -h mysqlhost -u username -p mydatabasename > dbdump.sql

Tuesday, March 8, 2011

Connect mysql with selenium



How to connect DB with seleniumRC

First you should now which table want to use and columns names.

Here we are connecting mysql and getting the username and password from "users" table. In this table "userEmail" & "password" columns.

A program can also explicitly load JDBC drivers at any time. For example, the my.sql.Driver is loaded with the following statement:
 Class.forName("my.sql.Driver");

When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization
and those loaded explicitly using the same classloader as the current applet or application.

Connect with Mysql/Oracle along with authentication

Connection conn = DriverManager.getConnection(url,"username","password");
then execute quires and store the data in a result set

Now you can use the stored data.
Here is an example for "Login", user email and password getting from the user table with mysql drivers.


// Connect my sql DB and get the user emailid with selenium  
package com.sasidhar.wf;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.thoughtworks.selenium.*;
import java.sql.DriverManager;
import java.util.regex.Pattern;

public class Test extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://your applicaiton url/", "*chrome");
}

public void testUntitled() throws Exception {
//this is mysql connection

Class.forName("com.mysql.jdbc.Driver") ;
String url = "jdbc:mysql://database host address/dbname";
Connection conn = DriverManager.getConnection(url,"username","password");
Statement stmt = conn.createStatement();
ResultSet result =  stmt.executeQuery("select useremail from user where userID=1");
while (result.next()) {
String emailaddress = result.getString("userEmail");

selenium.open("your applicaiton url/");
selenium.type("formField1", emailaddress);
selenium.type("formField2", "password");
selenium.click("Login");
selenium.waitForPageToLoad("30000");


}
}
}

Thursday, February 17, 2011

How to do regression testing, and can give one or two examples on that in the same application?


Genernally when we are doing Manual Testing - Regression 
testing can be done in two different scenarios.

1) When tester intially find the defects and sent it to 
developers for fixing the issue .Once the issues get fixed 
whatever the testing done by tester is regression testing 
means he will make sure that fixed defects does not effect 
the application.

2)When requirements changing dynamically means ex- you have 
done testing for application A successfully and suppose for 
same application when new features or functionality are 
added and tester will test the application to find out the 
impact it does the application with new requirements - this 
testing also termed as regression testing.

Wednesday, February 2, 2011

Create user, password and assign prviliges


# Connect to the local database server as user root
# You will be prompted for a password.
#
mysql -h localhost  -u root -p

#
# Now we see the 'mysql>' prompt and we can run
# the following to create a new database for Paul.
#
mysql> create database pauldb;
Query OK, 1 row affected (0.00 sec)

#
# Now we create the user paul and give him full
# permissions on the new database
mysql> grant CREATE,INSERT,DELETE,UPDATE,SELECT on pauldb.* to paul@localhost;
Query OK, 0 rows affected (0.00 sec)

#
# Next we set a password for this new user
#
mysql> set password for paul = password('mysecretpassword');
Query OK, 0 rows affected (0.00 sec)

#
# Cleanup and ext
mysql> flush privileges;
mysql> exit;

Tuesday, February 1, 2011

batch file for creating db in wondows


Create a batch file like creatingdb.bat
copy the following code in the batch file:
cd "D:\Program Files\MySQL\MySQL Server 6.0\bin"
mysql -uroot -proot database_name < e:/database.sql

database.sql should contain the following code

drop database database_name;
create database database_name;

use database_name;

source D:\project name\sql\File.sql
source D:\project name\sql\script.sql
source D:\project name\sql\script_users.sql


Multiple firefox instances


How to use Multiple profiles for Firefox
******************************************************
Download the firefox.exe
double click on firefox.exe
select custom method
uncheck for "quick launch, Desktop icon and startmenu icon"
after installation firefox
uncheck launch firefox and finish
go to "start -> Run"
Enter "firefox.exe -no-remote -P"
Create your profle
if you want to open firefox
go to "Start -> Run"
firefox.exe -no-remote -p
then you can select your profile and click start firefox

How to install multiple Firefox version in XP machine  
******************************************************
first, download and install FF3 to a directory DIFFERENT from the one FF2 is installed in. You might want to make a seperate start group for it too. DON'T start it up yet.

then run {pathToFF2}/firefox.exe -p

this will open the profile manager. Make a new profile, eg testProfile.

Now in your start menu shortcut to FF3, change it to "{pathToFF3}/firefox.exe" -p testProfile -no-remote.


How to open the firefox different versions
"c:\Program Files\Mozilla Firefox\FF2\firefox.exe"  -no-remote -P
"c:\Program Files\Mozilla Firefox\FF3\firefox.exe"  -no-remote -P
"c:\Program Files\Mozilla Firefox\FF3.5\firefox.exe"  -no-remote -P

-------------------------------------------------------------------------------------------------

TestNG

TestNG is yet an another framework to work in JAVA.


there are many features available in the TestNG that you will not find in JUnit.


TestNG Annotations
Following are some of the annotations we have used in our example
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked.
@AfterClass: The annotated method will be run after all the test methods in the current class have been run.
@Parameters: Describes how to pass parameters to a @Test method.
@Test: Marks a class or a method as part of the test.

If you look at the @BeforeClass and @AfterClass annotation they are same as of JUnit, the only difference is the method annoted with @BeforeClass or @AfterClass need not to be static as compared to the JUnit.



Google.java



import static org.testng.AssertJUnit.*;
import org.testng.annotations.*;
import com.thoughtworks.selenium.*;
public class Google {
private Selenium selenium;
@BeforeClass
public void startSelenium() {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com");
selenium.start();
selenium.open("http://www.google.com");
}
@AfterClass(alwaysRun=true)
public void stopSelenium() {
this.selenium.stop();
}
@Test(groups="search")
public void googling() {
try {
selenium.type("name=q", "sasidhar");
selenium.click("name=btnG");
selenium.waitForPageToLoad("60000");
assertTrue(selenium.isTextPresent("sasidhar"));
} catch (SeleniumException e) {
fail(e.getMessage());
}
}
}




Then compile the above program