Introduction to IO streams /external files in Selenium

Ratings:
(4)
Views:0
Banner-Img
  • Share this blog:

Introduction to IO streams /external files in Selenium

  • For better maintenance of the project we are going 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 maintenance 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 the 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 the lib folder.
  • Configure it in Eclipse by using the 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 “workspace”.
  • Take an Excel file and give the test data in the below format

User name (JanJo selenium)

Password(Selenium)

  • Save the Excel file with .xls formate [97-2003] in the 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

   At TekSlate, we offer resources that help you in learning various IT courses. 
We avail both written material and demo video tutorials. To gain in-depth knowledge and be on par with  practical experience,then explore Selenium Training
.

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;

Public FileinputStream fi;

Public Workbook w;

Public Sheet S;

@ ist

Public void verify login ( ) thrown Exception

{

fi = new File inputStream (“E:...ORlogin.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 login the functionality of mail.in.com with multiple sets of login credentials and provide the results in the below formula

Username password Result
Jan 30 selenium selenium Pass
Nagesh1 selenium Fail
April selenium selenium Pass
Nagesh 2 selenium fail

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

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

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

Step1:

Public void step1() throws Exception

{

FileoutputStream fo = new FileOutputStream (“E:work Space _10Am selenium resultlogin.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 an 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_10AMsaleniumTestdata….”)

Workbook w = workbook. Get workbook(fi);

Sheet S = w.get Sheet(0);

Fileoutput Stream fo = new file output Stream(“E:work space _10AMselenium 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 the standard time

2) explicit time:-it means wait until the elements are 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 the program:

Public static void method()

{

Login();

Wait(“Link= signout”);

Logout();

2 iIf we are while loop then sign out in not there then it keeps 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 an 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 an excel file for spicejet.com and run the script by using driver script

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

Step1:- create an Excel file by using the 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 framework
  • The Main is a hybrid framework.
  • It is a combination of test NG & data driver framework.
  • 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 your Framework?

Hybrid framework

2 it is a combination if test NG a data-driven framework

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

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

For an In-depth knowledge on Selenium, click on below

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox