Introduction to IO streams /external files in Selenium

Introduction to IO streams /external files  in Selenium

  • For better maintenance of the project we are goiing to take the test data and locators by using the external files like excel text pad, xml ,database e.t.c
  • We are going to use excel files to maintain the test data&locators.

Why Excel:-

  • We can store the data in a format with the help of rows& columns. so the maintain is easy.
  • If you save the excel .xls format [Excel 97-2003 workbook[xls]]
  • Then it can access in any operating system[platform independence]
  • As part of manual testing we are maintaining test cases & test data in Excel file .so we can directly access those files to take the test data.
  • To support Excel files we need to configure jx1.jar file in Eclipse.
  • We can download the jx1.jar file from our site selenium testing
  • http://selenium in for testing
  • Copy jx1.jar file in lib folder.
  • Configure it in Eclipse by using same steps as sikuli jar file

Test data:-

  • The data which we are going to use to test the application is known as test data.
  • Create a folder with the name “test data” under the project folder of “work space”.
  • Take an Excel file and give the test data in below format

User name (JanJo selenium)

Password(Selenium)

  • Save the Excel file with .xls formate [97-2003] in test data folder

* Write a program to login into mail .in.com by banking object repository from an excel file

Object repository:-

2repository mean a storage folder .object repository mean a storage folder which contains the element location like id, css, x path, name e.t.c.

2Create a folder with the name of workspace.

Take an Excel file and give the object repository in below format.

User name (f_ id)  pass word (f_ pwd)  sign (input _ sign in)

2  Save the Excel file in .Xis format [97 -2003] in or Folder

Inclined to build a profession as Selenium Developer? Then here is the blog post on Selenium Training In Chennai.

Assignment:

* Write a program to test the log in functionality of mail income by the rest data and object repository from 2

Different Excel Files:

Public class log in _ OR

{

Public web driver driver;

Public FileinputStream fi;

Public Workbook w;

Public Sheet S;

@ ist

Public void verify login ( ) thrown Exception

{

fi = new File inputStream (“E:\\...\\OR\\login.XIS”);

w = Workbook. Getworkbook(fi);

s= w.getsheet(“login”);

driver . Find  Element (By.id(s.getclass(0,1). Get content())) . send keys(Jan 30 selenium)

driver.Find Element …(1,1) ….(“selenium”)

driver. Find element (By.cssSelection(s.getcell(2,1).get content()) .click();

}

@ Test public void verify logout()from exe

{

* Write a program to test the login functionality with multiple sets of login

Assignment:

* Write a program to test the login functionality of the gmail.com with multiple sets of login credentials

* Test the log in functionality of mail.in.com with multiple sets of login credentials and provide the results in the below formula

UsernamepasswordResult
Jan 30 seleniumseleniumPass
Nagesh1seleniumFail
April seleniumseleniumPass
Nagesh 2seleniumfail

2 To accomplish the above scenario we need to fallow below 3 steps

  • Create an Excel File [Result File]
  • Add the complete i/p data to the created resuch file
  • Add a result column and provide the resuch an pass or fail based on the execution

2 Create a folder with the name ”Result” under the project folder of “work space 10” and capture all the results into this folder

Step1:

Public void step1() throws Exception

{

FileoutputStream fo = new FileOutputStream (“E:\\work Space _10Am \\ selenium\\ result\\login.XIS”);

Writable Work book wb = Workbook.createworkbook(fo);

Writetable Sheet ws = wb.create sheet (“Results” ,0);

Label un = new Label (0,0 “username”);

Label pw= new Label (1,0 “password”);

Label rs= new Label (2,0 “Result”);

  1. add cell(un);
  2. add cell(pw);
  3. add cell(rs);

}

Nested for loop syntax:    

For (int i= 0; I<3; i++)

{

For (int j= 0; j<2; j++)

{

Sysem .out.println(j,i);

}

}

Result:

j      i

0     0

1     0

0     1

1     1

0     2

1     2

Step 2: program

Public class add input data to result File

{

@Test

Public void step 2() throws exception

{

//1. Print the i/p data on the console

  1. create result file and add provide console output

FileinputStream fi = new FileinputStream(“E:\\workspace_10AM\salenium\\Testdata….”)

Workbook w = workbook. Get workbook(fi);

Sheet S = w.get Sheet(0);

Fileoutput Stream fo = new file output Stream(“E:\\work space _10AM\selenium \\result”)

Create table workbook wb = workbook.create workbook(fo);

Writeable sheet us = wb. Create sheet(“Result”,0);

For(int i=0; i< l.getrow(); i++)

{

For(int j=0; i< l.getcolumn(); j++)

{

s.o.p (s.getcell(j,i).getcontent());

Label un = new Label (j,i, s. getcell(j.i).get content());

Ws.add cell(un);

}

}

Cabel rs = new label (2,0,”result”);

Ws. Add cell(rs);

Ws. Write();

Wb.close();

}

Check out the top Selenium Interview Questions now!

Synchronization:-

It is two types

1) implicit time:-it is standard time

2) explicit time:-it means wait until the elements is available

Public void wait(String str)

{

For(int i=0; i<20; i++)

{

If(selenium .in element process(str))

{

Break

}

Else

s.o.p(i);

{

Thread.sleep(1000);

}

}

}

How we can use in program:

Public static void method()

{

Login();

Wait(“Link= signout”);

Logout();

2 iIf we are while loop then signout in not there then it keep out executing infinite times

X2 HOS 2 Admin 2 Admit

Y 2 HOS 2 Admin Advice 2 Admit

Interested to become master in Selenium? Enroll now for FREE demo on Selenium Training in New York City.

Data driver frame work:-

Develop the driver script [data driver frame work] from the scenario login & registration of mail.in.com

2to develop the driver script take the test data and object repository in an Excel file with below format

Public void reusable script() throws exception

{

Fileinput Stream fi = new fileinput Stream(“E:\\workspace_10AM \\selenium\\”)

Workspace w = workbook.getworkbook(fi);

Sheet s w.get sheet(“sheet1”);

For(int i= 1; i< s.get row(); i++)

{

If(s.getcell(2,i).get contents().Excelignore case(“textbox”))

{

If(selenium .inelement present(s.getcell(0,i).get content()))

{

Selenium .type(s.getcell(0,i).get content(), s.getcontent())

Assignment:-

2develop the test data and object repository in a excel file for spicejet.com and run the script by using driver script

àonce the exception is copltted provide the results in an Excel file[resilt file]

Step1:- create an Excel file by using file output stream

Step 2:-Add input data to the result file by using ‘j loop’[ nested for loop’]

Step3:-Add a result column and provide the result as pass or fail based or the execution.

  • Explain about your frame work
  • Main is hybrid frame work.
  • It is a combination of test NG & data driver frame work.
  • We can use both the advantage of data driver &test NG[key board driver]
  • We are using xml file to execute both the test scripts[class].

2 Explain about your Framework?

Hybrid frame work

2 it is a combination if test NG an data driven frame work

2 we can use both the advantages of data driven and Test NG[Key word Driver]

2 we are using XML file to executes both the test script[class]

For an Indepth knowledge on Selenium, click on below