Thứ Hai, 5 tháng 11, 2012

Data driven testing In Selenium using JXL

We saw all these post and many friends who are reading these posts found really interesting and said they are really simple and useful.
But in all the post we just saw the very basic stuff on Selenium, but once our test becomes complex, we need to deal with some real codes. Many of my friends who are dealing with manual QA see coding as the weird part in automation, all they want is Click record button, perform some operation, stop recording and replay the same. That’s fine for Selenium IDE, but moving forward we need to make our code more robust to withstand complex applications.
There are lots of limitations in using Selenium IDE, some are
  • Using Conditional Statements
  • Using External Data
  • Logging
  • Exception handling
  • Reporting etc
In this topic we are going to deal with one of the most important yet very useful stuff for automation in Selenium with is “Data Driven Testing”. We can drive Selenium testing using data sources like XML, Excel sheets, Database Tables etc.
But wait, what if I just need to store some of the application properties like Object Name, Application Window name, global properties etc, do I need to use the data sources you are talking about ?
Well, the answer is Yes or No, depending upon the complexity of your application, if your application has very few objects and their properties to be identified are very minimal, you can use “Property file” instead.
Here is the sample code to read data from Sample file in JAVA.
public void ReadProperty() throws IOException {
   System.out.println("In Read Property....");
   //Create Property Object
   Properties p = new Properties();
            //Load the Property file available in same package
   p.load(getClass().getResourceAsStream("objects.properties"));
            //Give the propery name to access
   String propName = p.getProperty("name");
            //Output the property value
   System.out.println(propName);
  }

Now if your application becomes very complex and you rely each and every data to be driven from external data sources, then you SHOULD use data sources like Excel, Database table etc.
Here we are going to talk about driving data from Excel sheet using JXL (JAVA EXCEL API). You can read more about JXL from the site, but for now, let’s consider JXL is an API to read and write data from Excel Sheets. We are going to use JXL’s Excel as our Dataprovider to read data from external data source. There are some other API available to read and write data from excel sheet like POI-HSSF and POI-XSSF , but we are going to deal only with JXL here.
Before getting started with JXL coding, let’s get to know some basic steps of how to read data from Excel sheet, below is the diagrammatic representation.
clip_image001
Well, here is how the code to start working with JXL.
Lets go with the diagrammatic representation.
Step 1
import java.io.File;
import java.util.Date;
import jxl.*; 
 
Workbook workbook = Workbook.getWorkbook(new File("C:\\data.xls"));
Step 2
Open worksheet
Sheet sheet = workbook.getSheet("sheet1");
We can also give the index of sheet as
Sheet sheet = workbook.getSheet(0);
Step 3
Read the data from Excel Cell
String value = sheets.getCell(Column, Row).getContents();
Here Column is the column number and row is the row number from the cell which you are interested to read data.
Step 4
Now close the worksheet
workbook.close();
That’s it !!!


Data Driven Testing in Selenium using JXL (Part 2)

Rating: 4.7/5 (12 votes cast)
We have learned what is Data driven testing and how we can use JXL to read data from Excel Sheets in Part 1 of our previous post. But the greatest question of the day is, how to use JXL for data driven testing ?. How can I use this in my Selenium framework which I have? What are the steps which has to be taken care to make my framework a data driven framework?
Well, for this I don’t want to bore you guys with lot of theoretical contents which you can always find some way or other, but I would like to show the real working code.
In order to perform data driven testing, all we need to do is create a reusable library file just for Excel using JXL. The library file need to have following basic functionality in hand, let say
Step 1 : Create a library file with all the below mentioned functionality
1. Open Excel Sheet
2. Read Excel Sheet Row Count
3. Read Cell value from a specified location
4. Create a Dictionary to store Excel Sheet Column name
5. Create a function to read from the Dictionary
The Source code looks like this.
/*
 * Author : Karthik KK
 * Description: Reusable Library file to perform Excel related operations
 * Date : 01/28/2012
 */
package DataDriver;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
 
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
 
public class ExcelSheetDriver {
 
 static Sheet wrksheet;
 static Workbook wrkbook =null;
 static Hashtable dict= new Hashtable();
 //Create a Constructor
 public ExcelSheetDriver(String ExcelSheetPath) throws BiffException, IOException
 {
  //Initialize
  wrkbook = Workbook.getWorkbook(new File(ExcelSheetPath));
  //For Demo purpose the excel sheet path is hardcoded, but not recommended :)
  wrksheet = wrkbook.getSheet("Sheet1");
 }
 
 //Returns the Number of Rows
 public static int RowCount()
 {
  return wrksheet.getRows();
 }
 
 //Returns the Cell value by taking row and Column values as argument
 public static String ReadCell(int column,int row)
 {
  return wrksheet.getCell(column,row).getContents();
 }
 
 //Create Column Dictionary to hold all the Column Names
 public static void ColumnDictionary()
 {
  //Iterate through all the columns in the Excel sheet and store the value in Hashtable
  for(int col=0;col < wrksheet.getColumns();col++)
  {
   dict.put(ReadCell(col,0), col);
  }
 }
 
 //Read Column Names
 public static int GetCell(String colName)
 {
  try {
   int value;
   value = ((Integer) dict.get(colName)).intValue();
   return value;
  } catch (NullPointerException e) {
   return (0);
 
  }
 }
 
}

Next we are going to create actual test file which is going to perform intended operation, here we are going to perform Gmail login functionality.
Step 2: Create a TestNG Class file to perform Gmail Login
This TestNG class file should include
1. Opening a browser with Gmail
2. Perform User Name and password entry with different combinations of value by reading from Excel sheet
Source Code looks like this
package DataDriver;
 
/*
 * Author : Karthik KK
 * Description: To perform Gmail Login using Data driven approach
 * Date : 01/28/2012
 */
 
import java.io.IOException;
import jxl.read.biff.BiffException;
 
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
 
public class ReadDataTest {
 
  //Global initialization of Variables
  static ExcelSheetDriver xlsUtil;
  WebDriver driver = new InternetExplorerDriver();
 
  //Constructor to initialze Excel for Data source
  public ReadDataTest() throws BiffException, IOException
  {
  //Let's assume we have only one Excel File which holds all Testcases. weird :) Just for Demo !!!
     xlsUtil = new ExcelSheetDriver("D:\\Data.xls");
     //Load the Excel Sheet Col in to Dictionary for Further use in our Test cases.
     xlsUtil.ColumnDictionary();
  }
 
  @BeforeTest
  public void EnvironmentalSetup()
  {
   driver.get("http://www.gmail.com");
  }
 
  @Test
  /*
   * Author : Karthik KK
   * Description : To Perform login operation in Gmail
   */
  public void GmailLoginPage() throws InterruptedException {
 
   //Create a for loop.. for iterate through our Excel sheet for all the test cases.
   for(int rowCnt = 1;rowCnt < xlsUtil.RowCount();rowCnt++)
   {
 
    //Enter User Name by reading data from Excel
    WebElement userName = driver.findElement(By.name("Email"));
    userName.clear();
    userName.sendKeys(xlsUtil.ReadCell(xlsUtil.GetCell("EmailUserName"), rowCnt));
 
    //Enter Password
    WebElement password = driver.findElement(By.name("Passwd"));
    password.clear();
    password.sendKeys(xlsUtil.ReadCell(xlsUtil.GetCell("Emailpassword"), rowCnt));
 
    //Click on the Sign In Button
    WebElement signin = driver.findElement(By.name("signIn"));
    signin.click();
 
    //Sleep for some time,so that we can see things in action @ Screen :)
    Thread.sleep(2000);
   }
  }
 
}

Step 3: Create a actual Excel Sheet which holds the data to be supplied in TestNG class in above step
Just create a Excel sheet, which looks something like this.
excel

Step 4 : Try executing the code
Just try executing the code, Note in the above code I have place excel sheet in my D:\ drive, you can place it anywhere in machine and change the same in code.
Your Gmail screen looks like this at the end of test by executing all the above test data’s
gmail

Well you can download the full working source code from here
That’s it !!!

How Selenium Works ?

How Selenium Works ?

Rating: 4.9/5 (7 votes cast)
We have seen many topics on Selenium ranging from working from Selenium IDE to Creating a data driven framework in Selenium, but let’s turn back our attention on how Selenium actually works. Since we have seen all the magic selenium has did for us by just writing very simple codes.
Did we ever thought how selenium opens a browser, the pages and communicates with the pages and perform operations we have specified in the code we have written? Did you ever heard about Selenese? Do you know Selenium server actually understand only Selenese command? Where did your actual code turns into selenese command?
Well we are going to discuss all the above questions in this topic of how Selenium works
We know there is a Selenium Server (Selenium RC Server), Selenium Client driver (driver specific to languages such as C#, JAVA etc) and we use them in our famous Eclipse IDE for writing code.
Once we start running a code from Eclipse IDE following stuffs will happen behind the scenes

1. The Client driver will first establishes a connection with Selenium server.
2. Selenium Server will do following
a. It will create a session for that particular request
b. It will launch the desired browser (Specified in the code IE,FF,Chrome etc)
c. Loads the Selenium cores Javascript file into the specified browser (So as selenium server will have handle with the webpage for performing Selenese action)
3. Now the Client driver will send the program that we have written in eclipse IDE as selenese (by making conversion) and send it to Selenium server.
4. Selenium server is intelligent enough to understand the selenese command and triggers the corresponding javascript execution in the web browser.
5. Here Selenium Server act as a “Proxy Server” between the AUT (Application under Test) and actual browser, due to the restriction of “Same origin policy” selenium server performs “Proxy Injection”.Being a proxy gives Selenium Server the capability of “lying” about the AUT’s real URL.
6. Now Selenium server requests the actual webserver for the page open request and then it receives the page and sends it to the browser. It will look something like this.
clip_image001
7. Now any operation or request which the browser makes will eventually passes through Selenium RC server to actual webserver and vice verse.
Well you can see the same behind the scenes operation by your own. Let us see how we can do that.
Step 1
Open the selenium server 2.15 from command prompt using the following command.
java -jar selenium-server-standalone-2.15.0.jar
Now your command prompt will look something like this.
clip_image003
Step 2
Now navigate to the URL http://127.0.0.1:4444/wd/hub, which is nothing but the default URL in which selenium server start, you can of course change the same if you want. Now your browser will have a page something like this
clip_image005
As you could see in the screenshot above, you have two buttons with create session and refresh sessions, as discussed in the point 2 above, first Selenium server will creates a session and then it starts the rest of operation by default.
Step 3
Lets create a session by clicking on the Create Session button in the browser we have, now this will ask us to select the browser
clip_image006
We will select Internet Explorer and click “OK” button, which will eventually create a session for us and launches a browser with empty page (Since we have not supplied any command to Selenium server at this point to open any URL or to perform any operations)
Now your Selenium URL page which you have opened in step 1 will looks something like this.
clip_image007
Here we have three more buttons with rest of steps we are going to perform.
In this topic we are not going to detail the Load scriptfunctionality, since this is beyond the scope of the topic which we are dealing with.
Anyways, this is how selenium actually works and performs the magic !!!
That’s it.

Thứ Ba, 31 tháng 7, 2012

Sách Kỹ năng mềm hàng đầu thế giới

[Mediafire.com] Download sách kỹ năng mềm hay hàng đầu thế giới 62



SÁCH DẠY  NHÂN CÁCH CỰC HAY CHO ANH EM


1. Con cái chúng ta đều giỏi

DOWNLOAD

2. Tôi tài giỏi - Bạn cũng thế

DOWNLOAD

3. Ước mơ của bạn nhất định thành hiện thực

DOWNLOAD

4. Đừng bao giờ đi ăn một mình


DOWNLOAD

5. Hẹn bạn trên đỉnh thành công

DOWNLOAD

6. Bí quyết về hưu sớm và giàu

DOWNLOAD

7. Tư duy lại tương lai

DOWNLOAD

8.Nguyên lý 80/20 - Bí quyết làm ít được nhiều

DOWNLOAD

9. Dạy trẻ phương pháp tư duy

DOWNLOAD

10. Bài giảng cuối cùng

DOWNLOAD

11.Phương pháp học tập siêu tốc

DOWNLOAD

12. Tất cả là thử thách

DOWNLOAD

13. 7 thói quen của bạn trẻ thành đạt

DOWNLOAD

14.Con đường phía trước

DOWNLOAD

15.Tay trắng làm nên

DOWNLOAD


16.Larry King - Những bí quyết giao tiếp

DOWNLOAD

pass: get4share.com


17.Suy nghĩ và làm giau - Napoleon Hill


DOWNLOAD

18.Dám thất bại

DOWNLOAD

19.Những bí ẩn của cuộc đời Dale Carnegie

DOWNLOAD

20.Người đàn ông đến từ sao hỏa - Đàn bà đến từ sao kim

DOWNLOAD

21.Đánh thức con người phi thường trong bạn

DOWNLOAD

22.Tư duy tồn tại

DOWNLOAD


23. Bí quyết tay trắng thành triệu phú


http://www.mediafire.com/?whjfu39qj42a1n6

24. Bí quyết gầy dựng cơ nghiệp bạc tỷ

http://www.mediafire.com/?641a64ym80szbz5

25. Làm chủ tư duy thay đổi vận mệnh

http://www.mediafire.com/?a3mamp7saj7yyfi


26.



- Dạy Con Làm Giàu – Cha Giàu Cha Nghèo – Tập I



- Dạy Con Làm Giàu – Để Được Thoải Mái Về Tiền Bạc – Tập II

- Dạy Con Làm Giàu – Để Trở Thành Nhà Đầu Tư Lão Luyện – Tập III

- Dạy Con Làm Giàu – Để Có Khởi Đầu Thuận Lợi Về Tài Chính – Tập IV

- Dạy Con Làm Giàu – Để Có Sức Mạnh Về Tài Chính – Tập V

http://www.mediafire.com/?i8nps0br5pwffkl-Dạy con làm giàu - Những bí mật về tiền bạc - Điều mà bạn không học ở nhà trường! - tập IX

http://www.mediafire.com/?83308q87phfcku5
27. Cảm hứng để sống theo 7 thói quen thành đạt


http://www.mediafire.com/?vfsskptgvhobc46

28. Sách dạy đọc nhanh của TONY BUZAN


http://www.mediafire.com/?yx74nj1iqbtobbw

29.

Đời thay đổi khi chúng ta thay đổi tập 1
http://www.mediafire.com/?yx74nj1iqbtobbw

Đời thay đổi khi chúng ta thay đổi tập 2
http://www.mediafire.com/?a164ky0e25197f3

Đời thay đổi khi chúng ta thay đổi tập 3
http://www.mediafire.com/?vp2emuqolj7n7pa

30. Tư duy đột phá

http://www.mediafire.com/?71586q76xiyp1tg

31.Những qui tắc trong cuộc sống

http://www.mediafire.com/?tgganbwvd8mbb5k

32. Thái độ quyết định thành công

http://www.mediafire.com/?pwzkd3123s88t17

33. 10 điều tạo nên số phận

http://www.mediafire.com/?2wgm9q1l84d3d5j

34.BARACK OBAMA - Hy vọng táo bạo

http://www.mediafire.com/?4dfkxunf4w261du

35.Hãy dể mọi chuyện đơn giản

http://www.mediafire.com/?723qlejodpmdtis

36.Good luck - Bí mật của may mắn

http://www.mediafire.com/?z44cfsjibrymgq5

37.Bí quyết để trở thành CEO xuất sắc

http://www.mediafire.com/?kyhmpcp5mhtyd27


38.Đắc nhân tâm

http://www.mediafire.com/?jbz8dwulhdiqkm4

39.Thế giới là phẳng

http://www.mediafire.com/?w2ccwey7g1ecttl

40.Tâm lý học đám đông


http://www.mediafire.com/?647syvj421z1f24

41.Suối nguồn tươi trẻ


http://www.mediafire.com/?gnj07cr1350mvle

42.Quẳng gánh lo đi và vui sống

http://www.mediafire.com/?ndkzphs1kfdy471

43. 10 nghịch lý cuộc sống


http://www.mediafire.com/?703cxs3o5a1y01d

44. 50 việc cần làm trước tuổi 20

http://www.mediafire.com/?mbj700g39hj8kf9

45. Ai lấy miếng pho mát của tôi?

http://www.mediafire.com/?3c7ae1k8qkb61km

46.Tại sao lại chần chừ
http://www.mediafire.com/?n0acytfpo56ueoj

47.Mục đích cao hơn tất cả

tập 1 http://www.mediafire.com/?9rd9jfs4zjtd06v

48.Trưởng thành - Trách nhiệm là chính mình

http://www.mediafire.com/?m0eo7n22mjq8dvf

49. 5 ngôn ngữ tình yêu dành cho bạn trẻ

http://www.mediafire.com/?c7rvcl8ppgp171i

50.Dám nghĩ lớn

http://www.mediafire.com/?n2jl7ieiib4150z

51. Bí mật tình yêu
tập 1 http://www.mediafire.com/?1mm7zybz4w5rrdr
tập 2 http://www.mediafire.com/?2eqaa3ee3ak3e8i


52.Tư duy tích cực - Bạn chính là những gì bạn nghĩ

http://www.mediafire.com/?m69v9ui5xx7pp4b

53.Đi tìm ý nghĩa cuộc sống

http://www.mediafire.com/?69ba2fi0ibdlmae

54.Không gì là không thể

http://www.mediafire.com/?i50scgc5dthdc34



55. Từ tốt đến vĩ đại


http://www.mediafire.com/?14oxr76ozjs6aeh



56.Tư duy tích cực - Bạn chính là những gì bạn nghĩ


http://www.mediafire.com/?m69v9ui5xx7pp4b



57. 10 câu nói bất hủ của Bill Gate


http://www.mediafire.com/?53uxwow0513b4s1



58.Bí mật của cảm hứng và say mê


http://www.mediafire.com/?pk8wuwdr1g56ghk



59.Bí quyết đạt được ước mơ


http://www.mediafire.com/?s87zk1fqz751sda



60.Dám chấp nhận


http://www.mediafire.com/?edr722wey8gsarq



61.Hành trình trở thành nhà lãnh đạo


http://www.mediafire.com/?escmxlwppbrbacd



60.I can do it – Tin vào chính mình


http://www.mediafire.com/?bxca92x8bz2e7z0



62.Tâm hồn cao thượng


http://www.mediafire.com/?6we46klxbhyx142



63.Tay không gầy dựng cơ đồ


http://www.mediafire.com/?7klh4kc5y584r23



64.Người giỏi không phải là người làm tất cả

http://www.mediafire.com/?9zp9d15le98uz39



65.Napoleon Hill - Tư duy làm giàu

http://www.mediafire.com/?wq246h0vnhv9t7r



66.Cuốn sách hoàn hảo về ngôn ngữ cơ thể

http://www.mediafire.com/?fe51uwilgs3sxsh



67. 7 A HA Khơi sáng tinh thần và giải toả stress

http://www.mediafire.com/?o0aef09agii2247



68.50 công ty làm thay đổi thế giới

http://www.mediafire.com/?abxl31nc29382fu



69.Học cách trò chuyện với bất cứ ai, ở bất cứ nơi nào và bất cứ khi nào

http://www.mediafire.com/?xm3oazo7ffq8ice



70.Hướng dẫn nhanh cách tăng cường trí nhớ của bạn

http://www.mediafire.com/?mc6a91tkm5jje9c



71.Không thể bị lừa đối

http://www.mediafire.com/?53f2tds2mbvw4qu



72.Kinh nghiệm của các thiên tài

http://www.mediafire.com/?3puqgpcmzgqex6b



73.Rèn nghị lực để lập thân

http://www.mediafire.com/?s4fu81xmm3gnfb9


74. Sáu chiếc mũ tư duy




http://www.mediafire.com/?lzo2zfadcpjnqmc



75.Sức mạnh tình bạn

http://www.mediafire.com/?u7rpuds232nqyip



76.[audio]Để hiệu quả trong công việc

http://www.mediafire.com/?y496dwa9b0m2hdn



77.Bí quyết tư duy triệu phú

http://www.mediafire.com/?8n7edzldxe3l47g



78. 100 qui luật bất biến để thành công trong kinh doanh

http://www.mediafire.com/?pyf0jc6fcyhl5ny



79.Nghệ thuật chinh phục khách hàng

http://www.mediafire.com/?732avv8vwcx66nj



80.MLM và những bí quyết (Tom Shriter)

http://www.mediafire.com/?1l5ecqauwwv8c8a



81.Kiếm tiền trên mạng cùng john chow

ttp://www.mediafire.com/?13j9tub7u1fxhdp



82.Người bán hàng vĩ đại nhất thế giới

http://www.mediafire.com/?ybn11wt2zmo61d3



83. 99 Khoảnh khắc trong đời người

http://www.mediafire.com/?6rom6x4gjpr76ac



84.Kỹ năng quản lí thời gian

http://www.mediafire.com/?5xrbi8t553qha3b


85.Google - câu chuyện thần kì

http://www.mediafire.com/?72c3gm8ofc1c81f