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

Wednesday, November 24, 2010

Enterprise Tester installation

Enterprise Tester Installation :
http://www.catchlimited.com/index.php?page=enterprise-tester
Register this website and login
Download Enterprise tester
Unzip Enterprise tester
Double click on Enterprise tester and wait for complete installation
Install 'mysql'
Create Database as 'etester'
Go to the 'Enterprise Tester' home path >> open web.config file
setup the mysql configuration
( add name="Default" connectionString="Server=machine ip address;Database='database name';Uid=root;Pwd=root;" )
Open the 'Enterprise tester'  from start menu program files
It will open browser (firefox) with "localhost/Enterprise tester/home
There is 3steps to complete the configuration
1. It will ask the Admin details
2. Enter the organization details
3. Enter the license key from registered website then 'save'
( License key you will get from registered website, Just login the website then come here to the 3rd step, access link 'click here' then it will take you to the generate license page, enter your server key and click 'generate license' button)
4. login with admin then use it...


Enjoy with work ...hahaha