Session 45 – Selenium with Java | TestNG | DataProvider… — Transcript

Learn TestNG parameterization using DataProviders and XML files for data-driven and parallel testing in Selenium with Java.

Key Takeaways

  • DataProvider annotation simplifies data-driven testing by eliminating manual loops.
  • Parameterization via XML files supports parallel test execution across multiple environments.
  • Test data can be hardcoded for small sets or dynamically read from Excel for larger data sets.
  • DataProvider methods return data arrays that control how many times a test method runs.
  • Understanding both DataProvider and XML parameterization is essential for effective TestNG automation.

Summary

  • Parameterization in TestNG allows passing parameters to test methods at runtime.
  • Two main ways of parameterization: DataProvider annotation and XML file parameters.
  • DataProvider is used for data-driven testing, enabling multiple test executions with different data sets without looping.
  • XML file parameterization is primarily used for parallel testing, such as running tests on multiple browsers simultaneously.
  • DataProvider methods create and return test data, which can be hardcoded or read from an Excel file.
  • Using DataProvider avoids explicit looping in test methods by automatically repeating tests for each data set.
  • For large data sets, Excel files are preferred to store test data, which is read into a two-dimensional array inside the DataProvider.
  • Earlier data-driven testing involved looping through Excel rows and passing data directly to tests; DataProvider abstracts this process.
  • The session focuses first on DataProvider usage before covering XML file parameterization.
  • Combining Excel data reading with DataProvider enhances maintainability and scalability of test automation.

Full Transcript — Download SRT & Markdown

00:05
Speaker A
So in today's session, we'll see one of the most important topics in TestNG, which is parameterization.
00:21
Speaker A
Parameterization means we can pass parameters to the test. Suppose in your test class,
00:38
Speaker A
we can create multiple test methods. At runtime, we can pass parameters to the test methods,
00:52
Speaker A
which is basically called parameterization. We can achieve parameterization in two different ways. One is using
01:11
Speaker A
the data provider annotation, and the other is using XML file. So data provider annotation
01:27
Speaker A
is also one of the annotations we have. Earlier, we have seen some annotations, and data provider is also one of them. This is
01:45
Speaker A
especially used for data-driven testing in TestNG. We'll discuss that. The next type of parameterization is using an XML file. We can pass parameters to the test methods using an XML file.
02:03
Speaker A
This approach is especially used for parallel testing. Suppose if you want to execute your test case on multiple browsers at the same time,
02:20
Speaker A
then you can use this approach. Both come under parameterization because we are going to
02:35
Speaker A
pass some parameters to the test method.
02:51
Speaker A
The first one is especially used for data-driven testing. Data-driven testing is used when you have multiple test inputs or multiple test data, and we can pass that to the test method. So for that,
03:03
Speaker A
we can use the data provider for data-driven testing. Both come under the parameterization concept, but both are totally different.
03:16
Speaker A
These two cannot be compared. For data-driven testing, we use data provider annotation in TestNG. Especially to perform
03:29
Speaker A
parallel testing, we pass the parameters from the XML.
03:45
Speaker A
Today, we'll discuss both, one after another. First, let us start with the data provider annotation. What is the use of the data provider annotation? You will get a lot of questions on these two
04:01
Speaker A
concepts. Listen very carefully. I'll cover most of the points. Earlier, we already saw how we can perform data-driven testing using an Excel file.
04:19
Speaker A
We specify the data in the Excel file, and
04:36
Speaker A
we have written some logic which reads the Excel file data. Once you read the data from the Excel file, we pass it to the application, and
04:52
Speaker A
then we capture some output and do some validations. So earlier, we have done
05:07
Speaker A
data-driven testing using an Excel file as a source. In the Excel file, we specify the test data, right? To read the data from the Excel file, like rows and columns, all the data, we have to read one
05:23
Speaker A
after another, and we pass it to the application. For that, what we have done is we have written a looping statement. Only through looping statements, we have achieved it. We have captured the first row data and passed it to the application.
05:37
Speaker A
Once it is done, then again, we have captured another row data and passed it to the application. So this is the process. We continued till all the rows are completed from the Excel file or Excel sheet, right? So there, the looping
05:56
Speaker A
is most important. Without looping, we cannot repeat all the rows and all the cells. But here, the data provider annotation provides,
06:13
Speaker A
without using any looping statement, we can execute a set of
06:27
Speaker A
steps multiple times with different sets of data. So that kind of facility is provided by the data provider. Data provider is basically a method which will create some data and pass it to another test method, which is called
06:42
Speaker A
the data provider annotation. Let me give you an example of how we can differentiate data-driven testing we did earlier and how we can do it by using the data provider annotation.
06:58
Speaker A
Earlier, we had some data in an Excel file. This is our
07:11
Speaker A
Excel file, and we read this data through your automation script. We used a looping statement to read each and every row one after another, and once you read the row, you pass it to the application under test. So this is the
07:27
Speaker A
process we have done. This loop set of statements we repeated multiple times because in each and every iteration, we got another row from the Excel sheet.
07:43
Speaker A
Now we will use a different approach. The approach is, okay, anyway, we'll use the Excel file along with the data provider, but how exactly data provider is working? For example, let's say here I have written one test method. Let's say this is our test method. I have written some piece of code, and this is actually doing
07:59
Speaker A
the test on the application under test. Now, this particular test method requires some test data, and now this test method I want to repeat multiple times without using any looping statement. I do not use any looping statement, but still, I want
08:11
Speaker A
to execute this test method multiple times. Let's say I have written one test for login, and this login test method I want to repeat multiple times, but at the same time, I don't want to use any looping statement. I just want
08:28
Speaker A
to repeat this multiple times with different sets of data.
08:40
Speaker A
For that, we will create one more method like this, and what this method will do is this method will create some test data and pass it to the test method. This type
08:52
Speaker A
of method we can specify with the data provider annotation. So what is the purpose of this method? This method will prepare some test data and return it to another test method in
09:06
Speaker A
the same class. Now, this particular test method will repeat multiple times. Let's say suppose here I'm passing five inputs. The data provider method is passing five inputs, so the test method will repeat five times automatically. We don't
09:20
Speaker A
need to use any looping statement here. Depending upon the number of inputs provided by the data provider, our test method will repeat those many times. Here, the looping statement we can avoid. That's the first important point.
09:36
Speaker A
What is the advantage of using the data provider method? First point, we can avoid writing a looping statement. Now, the second thing, earlier we have done data-driven testing using an Excel file, right? Suppose if you have a few inputs or three to five
09:52
Speaker A
inputs, we can directly hard code the data in our data provider method, and that we can return. Let me complete first and then ask the questions.
10:06
Speaker A
This requires a lot of explanation to understand this. All your questions will be clarified.
10:19
Speaker A
First, listen. Inside the data provider method, we can specify the test data as hard-coded data. For example, if you have three to four inputs, we can specify inside the data provider method, and you can return it.
10:32
Speaker A
Suppose if you have huge data, let's say you have 10 inputs, 20 inputs, 100 inputs, it is not best practice to specify the data inside your code. The code should not contain any data. So we will have an Excel file again.
10:47
Speaker A
In the Excel file, we'll specify the data. Now, this data provider method itself has logic which will read the entire Excel data and keep that data in a two-dimensional array. Here, separate logic we need to write inside the data provider
11:02
Speaker A
method. If you have a small set of data, you can directly hard code the data in the data provider method and return it to the test method. Suppose if you have huge data, you can specify it in
11:15
Speaker A
the Excel sheet and read the entire data from Excel, keep it in the two-dimensional array, and that data you can return. This is another way. So here, basically, we are using both concepts: using Excel file and using data provider.
11:29
Speaker A
Earlier, we already saw how to read data from Excel file using the Excel utility concept, right? Excel utils we have created. That process is the same, but earlier, how we have done it is as soon as you read this particular row data, immediately we
11:44
Speaker A
pass it to the application and do the testing. But now, what we will do is as soon as we read the rows one by one, each row data, we will put inside the two-dimensional array. Once all the
11:59
Speaker A
data is available in the two-dimensional array, then we will pass the data to the test method, and the test method will repeat multiple times based on the number of inputs. So this is the act.
12:14
Speaker A
parameterizing the data XML file parameterization is different okay I will tell you that one later first focus on this how we can create data provider method how we can pass the data to the another test so we'll try to understand
12:29
Speaker A
this with an example how we can do data driven testing using data provider method and what is the usage of what is the advantage of using data provider method is we can avoid looping without using any looping statement if you want
12:45
Speaker A
to repeat the test method multiple times you can use data provider annotation method so let me show you the implementation step by step very very important concept now go back to the eclipse and creating new package day 45 okay so inside this class I'm
13:14
Speaker A
creating a inside the package I'm creating a new class called Data provider demo okay in this I'm not integrating Excel file so that logic we'll see later so we should not take any main method because we are creating the test Ang
13:33
Speaker A
class okay so inside this data provider uh I'm going to create this is a new class which is created so I'm going to create a few uh test method so first of all I'll create one method called setup in this I will set up the browser
13:51
Speaker A
so I can say wi setup and this I want to execute only one time only one time before starting the test test okay so let me create the method first so I can say void test login so this is the actual test method
14:08
Speaker A
and after that tear down means I just want to closing all the stuff so now the setup method I want to create something Lo something like just I want to create a driver instance I want to launch my
14:22
Speaker A
browser so that part I will put inside the setup method and after that I will do login and after that I will close my browser that I will put in the tier down method okay so now setup method I want
14:36
Speaker A
to execute only once only once before starting the test methods only once so what which annotation we can specify here only once I want executing which annotation we can specify before class not before test if you want to say
14:56
Speaker A
before test again we need to go with XML file we need to specify two test entries okay so just before class so only one time I want to execute my setup method so we can say before class annotation import this now test login is
15:11
Speaker A
actual test method so I can say test annotation for this and T method I will execute only once after completion of the login so which annotation we can specify after class after class okay now let us try to
15:30
Speaker A
implement them uh first of all setup method login and TI do meth so in the setup method I will initiate the driver instance and everything I will create a driver as a class variable so that I can access through all the methods web
15:45
Speaker A
driver driver now import this web driver now this driver I will initiate in the setup method driver equal to new Chrome driver so this will launch our browser and if you want to put some implicit weight here itself we can put driver dot
16:06
Speaker A
manage dot see I already told you that annotation when you create a before class after class is not mandatory okay if you do not want to do any activity after completion of the test method then you no need to specify after class not
16:25
Speaker A
necessary same thing is applicable for other annotations also we seen before method after method right so if you create a before method after method is not compulsory if you have to execute some method then you can put there
16:38
Speaker A
otherwise not necessary similarly before class after class before test after test before suit after suit we will just learn with the combination but only one annotation also you can specify only before class you can specify or only after class you can
16:53
Speaker A
specify it depends on how you are writing the test okay suppose I want to execute few steps before executing the test method so definitely I can create a before class similarly after completion of the test method again I want to
17:06
Speaker A
execute some more steps as an entry as an exit so that you can put in the after class so depends on that you can specify otherwise you can avoid no problem but most of the times every test is having
17:20
Speaker A
some entry having some exit entry means what creating the browser launching the base launching your application that is a prerequisite that you can always keep inside the before class after completion of the test we will close our application we will log out from
17:35
Speaker A
application most of the times right that you can put in the after class so driver. manage do timeouts dot implicitly wait I can put some time here duration dot of seconds has said 10 okay so now I just initiated the
17:58
Speaker A
browser or driver inside the setup method so this will execute only once now in the test login I will create the actual test uh through which we can uh launch your application login all the process okay so I will put some piece of code
18:18
Speaker A
here so I'm just launching this page and after that I'm maximizing the page and then I'm entering the uh email address so for example here I can say some ABC gmail.com and here I will pass some password test at the 1 2
18:37
Speaker A
3 and here this is a login I'm clicking so I think this page you already seen let me open this application first okay so this is application I'm just launched this is again open Card application so here I'm passing email
18:54
Speaker A
address password clicking on the login so after clicking on the login uh then I'm verifying the dashboard page or my account page is displayed or not this is a my account page is displayed or not I'm getting the status and if the
19:09
Speaker A
status value is equal to true then I'm clicking on the log out and also I'm making my test method passed I'm using assertion here asset. asset equal to True okay so if if I'm getting the my account page after login what does it
19:25
Speaker A
mean my login is passed so again if you want want to take another input we have to click on the log out then it will come to the login page again you can pass another input so as soon as the
19:36
Speaker A
status become true I'm clicking on the log out and making my test method pass suppose if the status value is equal to not true then I'm making my test method fail asset. fail or you can use asset.
19:48
Speaker A
asset true is equal all fail can use same statement but instead of true it can pass false or if you want to directly fail your test method you can say s. fail so this this is the test I
19:59
Speaker A
have created for login this is the test I have created okay it will launch our application passing username and password clicking on the login capturing the my account text and if it is a true then log out from application and make
20:16
Speaker A
my test method passed else make my test method failed so this is the actual test so this I want to repeat multiple times with the different sets of email addresses and passwords Okay so so this is actual test
20:30
Speaker A
now come to the tier down in this I can say driver Dot close or quit whichever you want you can use okay so this is a way we can create the test so before class setup method will execute only
20:44
Speaker A
once and test login as of now it will execute only once and TI down also will execute only once so this is how normally we can create okay now if you pass valid username and valid password my test will
20:58
Speaker A
pass so let me pass a valid username and password here I'm passing my and this email Iden password which is already created earlier in the same application so I'm using it okay now let me run this run as test
21:16
Speaker A
R test okay so this is launched my page and your login is also successful my test is passed and as of now my test method is executing only one time with one set of data which I have passed here only only
21:45
Speaker A
one time it first initially it setup method then test login is got executed and then tear down which is automatically close my page so as of now this particular login test method will take only one combination of data one
21:59
Speaker A
username and password now my requirement is I want to repeat this login test multiple times with the different sets of data okay I want to login I want to execute this login test multiple times with the different sets of data and I'm
22:19
Speaker A
not going to use any looping statement inside this test log I don't want to change any code as it is as of now are are we using any looping statement in this no right there is no looping statement but still I want to execute
22:32
Speaker A
this test method multiple times with different sets of data that's my requirement so this we can achieve through data provider method okay so let's create one data provider method you can create anywhere in this class you can create data provider at the
22:46
Speaker A
beginning or at the end wherever you want you can create okay so how to create data provider method let me show you so here I'm going to create uh one method which is called Data provider method so I create just a for now I can say void
23:06
Speaker A
login data so I'm giving some name to login data and I can make this as a data provider annotation we have to specify otherwise this will consider as a normal Java method so we need to make that as a
23:20
Speaker A
data provider method we need to specify this annotation now what is the purpose of this method is creation of test data and returning the test data creation and returning the data that's the only purpose and once it is returning the
23:36
Speaker A
data so which suppose sometimes you may have multiple test methods so any test method can receive the data so I'll show you that so first let us create a new data provider method so login data is a name I have given inside this to
23:51
Speaker A
maintain multiple users and passwords I will create I will create one two-dimensional array I can a data two brackets inside this I will keep all the username and passwords inside this two Dimension array I can create multiple username and password so how can we
24:10
Speaker A
create multiple username and password inside the two Dimension array two rows and two columns we can have right so this is a two Dimension array I will create and multiple username and password I will mention so here I will
24:25
Speaker A
put all the users in the second column I will put all the passwords and first row second row third row okay so for that I created one two Dimension array so how we can stor the data in the two Dimension I'm not
24:38
Speaker A
specifying any size because tomorrow if you want to increase the data or decrease date we can do it so now I just want to have some data in the two Dimension I'm hardcoding this data but actually we need to get this data from
24:50
Speaker A
the Excel file for that we need to write a logic but here I'm just hardcoding some data so I already have some and the data should have a valid or invalid both we should have so I'm just having some
25:04
Speaker A
data here inside this two dimensional array right so this is how we can put data in the two Dimension array right have you guys remember the array session arrays class we have seen this part how we can store
25:21
Speaker A
data in the two dimensional array so this is actual two Dimension array so this is the first row username and password this is second row third row fourth row and fifth row so totally five rows we created in the twood dimensional
25:36
Speaker A
array and two columns First Column is having email addresses second column is having passwords and in this Su data is a valid data some of this invalid data okay so now in the data provider method we just created one two dimensional
25:53
Speaker A
array which contains data now once you have dat in the two dimensional array I'm going to return this I'm going to return two dimensional array and when you're returning the string type of data the return type should be string
26:13
Speaker A
only but are we returning single data or multiple data are we retaining only one string or multiple strings multiple right because array D array variable I'm passing array means what which contains the rows and columns so along with the data type we should
26:31
Speaker A
also specify array because we are returning two dimensional array of string type so the return type also should be twood dimensional array of string type okay but sometimes in this data we can have a different type for example
26:52
Speaker A
sometimes you may have integer and string combination sometimes you may have a Boolean sometimes you have some other characters so different kinds of data you can specify in the two Dimension array test data can be anything right so instead of keeping
27:05
Speaker A
string better to have object okay better to have object because the data object can have object kind of array can have any type of data it can hold all kinds of data right so better to have object and even return
27:20
Speaker A
type also can have object so this a normal standard format we can pass you can still return in string integer what whatever you want so better to keep object because tested data can be any type it allows to store any type of data
27:37
Speaker A
so I just created some two Dimension array which contains some data and we're returning it and the return return type is what object type of an array so this is another important inry question so data provider method what is
27:54
Speaker A
the return type of data provider method what is a return type of data provider method so data provider method always returns two dimensional array which can be a string or can be object can be or any other data type but most of the
28:10
Speaker A
times it will return two dimensional object type of an array okay so this is how we can specify we can create a data provider method that's it here also we are not going to write any looping statement for now because we out coded
28:24
Speaker A
all the data okay but in the real scenario we should not hardcode like this we will get this data from Excel sheet and store in the two two Dimension array then we will return it the process is same only
28:38
Speaker A
thing is instead of hardcoding the data we will write a small looping statement through which we can get the data from Excel file so the purpose of data provider method is what creating the data test data and returning it that's
28:55
Speaker A
it it it will not do any testing it will not interact with any type of applications it is only preparing the test data and returning the data that's it okay now this is the data provider method fine now I want to use this data
29:10
Speaker A
in our test method in the login test method we'll repeat multiple times right by taking this particular data so how it is possible the first thing is whenever you create a data provider annotation we have to give some name to
29:29
Speaker A
that there is one attribute called name okay so the test data most of the times 99% of the times we use Excel files because Excel file is most convenient way to specify the data because all the rows data will be
29:46
Speaker A
aligned in the rows and columns in cell format so it is very convenient and most comfortable and flexible so that's the reason most of the times we get the data from only Excel sheets okay sometimes very rare cases we can get the data from
30:01
Speaker A
the notepad we can get the data from the databases tables if the database contains a table from that also we can get the data but ultimately even if you read the data from the database or notepad or whatever ultimately we will
30:13
Speaker A
host the data in the Excel sheet and through utility file Excel utility file we will read data from Excel file okay so properties file also we can use in the last classes we have seen how to read data from the properties file right
30:27
Speaker A
properties files we can use as an alternative Excel file properties file and database these are the only three options most of the times we use and database is also very rare case okay why because instead of writing the code for
30:40
Speaker A
database and everything we can directly export data from the database table to Excel file in the database itself we have some predefined options to export the table data in Excel file so we'll use that approach so we'll export table
30:54
Speaker A
data in Excel file and that Excel file we will use for automation testing or especially data driven testing okay even Json files in API testing we Json files will play important role but web testing Json files we not use most of the times
31:12
Speaker A
so Json files XML files these two files very popularly used only in API testing Excel files and properties files so these two files popularly used in web testing remember this point okay when you do web testing data will be maintain
31:29
Speaker A
properties file in Excel files when I do API testing then data will be maintained in the Json files or in XML files so that is a combination all right so when you create your data provider method you have to
31:44
Speaker A
specify an attribute called name so we need to give some name to the data provider method name in the sense not not name of the method additionally we have to give some name to the data provider so I'll tell you here I'll say
31:56
Speaker A
DP some name I have given so why this name is given uh we have to give I'll tell you so this is the data provider method which we created I have given some name to this now come to the main
32:07
Speaker A
test method so how this test method will know the data is provided by the data provider method because you may have multiple data provider methods also you may have multiple data provider methods but in that particular case how this
32:22
Speaker A
test login method will know about which data provider method is providing the data so we need to establish for connection right so test method should know from which data provider the data is coming from for that reason here in
32:36
Speaker A
the test annotation we will pass one more parameter called Data provider equal to whatever name we have given to this data provider the same name we have to provide here okay this is the connection so now the test login method will know the data
32:57
Speaker A
is coming from which method DP that is our data provider and if you look at here this data provider is annotation this is one of The annotation start with uppercase character and here this data provider is one of the
33:16
Speaker A
attribute of the test annotation so it is starting from the lowercase character okay so here we have to give some name to the data provider and with the same name we have to pass it here so the test login method will
33:32
Speaker A
know data is coming from DP which is data provider method which we already created fine so data provider method will return username and password in every round of execution username email address and password will be returned so this particular method also should
33:51
Speaker A
receive those parameters how we can receive those parameter here I will create a string email Comm string password so two parameter I can specify now these two parameters will receive the data from the data provider and instead of hardcoding this data I will
34:11
Speaker A
just pass it here email because these are the variables local variables email and password so this particular two parameters will receive email address and password and it will substitute here and it will do the validation so data provider method is passing a
34:32
Speaker A
different type of data different combinations of data and our test method will receive the data one after another and do the entire process for each and every email ID the script will be executed multiple times so have we used any looping
34:48
Speaker A
statement to reputation for this no there is no looping statement there is no looping statement so data provider how many inputs it is passing those many number of times test login method will execute okay now let us try to execute
35:05
Speaker A
so this is must and should so the name attribute we have to specify for data provider anation with the same name we have to refer data provider okay so otherwise the test login method will don't know which data
35:18
Speaker A
provider is passing the data all right now let us try to execute run as just notice how it is executing without having any looping statement see this this is my first email address not matching because this is invalid data I have
35:46
Speaker A
provided now it is taking second input it is also invalid now it is taking another input I think this is the third one and this is also invalid only the one combination I put valid data okay now this is valid data now it
36:16
Speaker A
is successfully login now again it is taking another data this is again invalid data done so if you look at the results so first time it is taking ABC the gmail.com test123 you can see this is the first input second time it is
36:41
Speaker A
taking XY gmail.com this is my second input third time John gmail.com next time this is actual valid data which is got passed and the next time the last time it is taking this one this is also failed see it is taking all the
36:59
Speaker A
combinations of data one after another and execution is happen the same test method is got repeated multiple times the same test method which is repeated multiple times with the different sets of data which are passed through data provider
37:15
Speaker A
method okay so whenever I say index again we have to write a looping statement here we have not using we are not using any looping statement that is a beauty of the data provider method that's the main advantage of the data
37:29
Speaker A
provider method so here we don't need to do any kind of indexing or anything no index is required no for Loops are required anything just it will return the data from the two Dimension array and in the test method it will read the
37:43
Speaker A
first input and do everything again take the second input and then do everything third input and repeat all the steps so this test method will repeat multiple times based upon the number of inputs we have passed through data provider method
37:58
Speaker A
here even though it is an array concept we don't need to use any index we don't need to write any F Loop so that is a main advantage of data provider method so data provider method will take care
38:07
Speaker A
of all those things repetion indexing looping all those things will be taken care by the data provider method itself so we don't need to bother about that how exactly it is doing internally okay so how many inputs we
38:21
Speaker A
are passing here those many number of times the test method will execute Okay so without using any looping statement the test method will repeat multiple times with multiple sets of data so every time you're getting the new email and password from the data
38:36
Speaker A
provider method and execution will happen and once it is done it will take another email and password then again execution been done so this is just like a enhanced F Loop in enhanced F Loop we are not putting any condition
38:51
Speaker A
initialization incrementation nothing right how many rows we have in are those many times automatically it will read one after another so once the rows are completed it will stop execution it is also working in the similar fashion so
39:03
Speaker A
it will read first row execution is done next row next row next row once all the rows are completed then it will stop executing okay so in whichever format we are passing the data because both are strings here right both are strings so
39:19
Speaker A
here both the parameters should be string so depends upon the type of data you have to provide the type of variables the type you should exactly match email address is always string password is also always string right so
39:33
Speaker A
I provid a string here suppose tomorrow if you pass some numbers or some other type of data accordingly you have to change the data type into the parameters okay so based upon the type it will automatically recognize because
39:50
Speaker A
earlier we already seen how to call the methods right if the method is accepting two string parameters we need to pass two strings if the method is accepting two number parameters then we have to pass two integers similarly here we are
40:03
Speaker A
passing two strings actually so the par parameter should be also strings okay so everybody's understood about this data provider method how to create a data provider method and how we can use the data provider method to repeat the test multiple
40:24
Speaker A
times okay and remember this data provider method is always rning two dimensional array only even if you have a 10 columns 10 inputs still it will return two Dimension because in the two Dimension we can create n number of rows
40:41
Speaker A
n number of columns right two Dimension means not only two rows and two columns it can have n number of rows n number of columns so the data can be increased no problem still it is a two dimensional
40:52
Speaker A
array and most important point you need to remember is this one whenever you create data provider method the name attribute must be specified because if you want to refer suppose this is a test login method and from where this is
41:08
Speaker A
getting the data how this test login method will know which data provider method is providing the data so that the reason we have to specify here data provider is equal to DP okay for example if you have a multiple data provider
41:21
Speaker A
methods and multiple test methods then how we can handle this so let us see this example let's say I have test method one another test method two and I have two data provider methods so said this is dp1 and this is dp2 two data provider
41:40
Speaker A
methods okay now the name here is the dp1 itself and here the name is dp2 itself now have two different test methods two data provider methods right so this is data provider and this is also data provider so here I have given
41:58
Speaker A
name attribute equal to dp1 here also I have given name attribute dp2 same name we cannot give okay now in the test method one I want to use this particular data provider method I want to get the data
42:13
Speaker A
from the dp1 so here what you can say in the test annotation you can specify so data provider equal to what dp1 that you can specify so this test method one we'll take the data from the data provider one so this is how we need to
42:32
Speaker A
combine similarly test method two I want to get the data from the dp2 data provider method two so here I can say at the test annotation here you can specify so data provider equal name equal to dp2 like this you can specify so now the
42:49
Speaker A
test method two will get the data from the another data Pro method so when in single class you can have multiple data multiple test methods and you can also have multiple data provider methods also okay but in the realtime projects
43:06
Speaker A
in the projects in the framework what you will do is we don't create these data provider methods specific to the class we will create a separate class which contains only data provider methods let's say you can have five to
43:23
Speaker A
10 data provider methods in one single class okay and you will have a multiple test cases multiple test case classes so if you want to use this data provider method in whichever class you want you can use it so this is the approach we
43:38
Speaker A
will follow so most of the times why because if you create this data provider within one single class right so this data provider I cannot use it for another test another class so that's the reason we will make all data provider
43:52
Speaker A
methods which are required in your project we'll keep everything in one single class all which contains only data provider methods that we will refer in multiple classes wherever you want okay and these data provider methods we don't need to specific static
44:08
Speaker A
public no nothing those access modifiers we never use and these data provider methods we can directly specify in the data provider parameter okay so in the framework I will explain more detail how we can specify all the data providers in one
44:26
Speaker A
single class how we can use them in multiple classes so that is Again part of the framework that I will show you another thing which we have missed here is how data provider get the data from the Excel sheet so suppose data is there
44:40
Speaker A
in Excel sheet so the data provider will get entire data from Excel sheet and store in the twood dimension array and that will be returned to the test case so this entire process you will see in the framework
44:54
Speaker A
concept yes all the classes can easily recognize as data providers from the single class so based on the names we can recognize so that's the reason name is most important so whenever you create a data provider method we have to provide the name
45:10
Speaker A
attribute so this is mandatory required this is mandate required okay so now I'm going to show you one few more options in this data provider so so far everybody's clear how we can create a data provider annotation method and how we can refer in the test
45:28
Speaker A
method how exactly the test method will repeat multiple times so the main benefit of data provider is what without using any looping statement we can repeat our test method multiple times okay so my requirement is suppose I have
45:43
Speaker A
five inputs here and I don't want to pass all five inputs to the test method so as of now my test method is executing five times because I'm passing five inputs but I don't want to repeat my test for all five inputs I I I want to
46:02
Speaker A
choose the inputs based upon my choice for example my test method I want to execute only for first input and the last input only two times I want to repeat or I want to execute my test in test method only for first three inputs
46:17
Speaker A
or last three inputs so how we can manage it so that you can manage by adding one more attribute here comma in the data provider oration itself we can pass one more attribute called indes indes indes equal to in the curly
46:38
Speaker A
brace you can specify so how many inputs you want to pass let's say first one this is a zero right so this is a 0o 1 2 3 4 because array index start from zero so this is a zero this is one 2 3 4 so I
46:52
Speaker A
want to pass only first two inputs to the test method only two times it will execute so I can say 0 comma 1 IND this is 0 comma 1 when I say 0 comma 1 only zero input and first input
47:07
Speaker A
only these two will be taken so now my test method will execute only two times by taking two inputs only two inputs zero and one let's execute and see this is the one more option which is very very helpful see the first input it
47:24
Speaker A
is taken my test is failed this is invalid input and then it will take another input this is my second input and this is also invalid so this will also should fail and finally close my browser I put waight and so it is taking
47:50
Speaker A
yeah now we can see this so first time abc gmail.com it is taken zero input second time x at gmail.com is taken that's the first one zero index one index so it is taking only two both the times it is got failed okay suppose I
48:07
Speaker A
want to take a first one and last one okay suppose I want to take this one and I want to take this one zero this is a zero 1 2 3 4 so 0o and four these two inputs I want to take I can say 0 comma
48:25
Speaker A
four so this is not the rate change actually so 0 comma 4 means it is not 0 to 4 0o element and fourth element okay so I say 0 comma four let me remove this weight so this will take much
48:47
Speaker A
time yeah it is specific to the index so now it is taking the first input now it is the second input and both are invalid data so both the times it will fail done I look at this so I have given
49:17
Speaker A
zero and four Z is a ABC gmail.com it is got failed the last one John Kennedy gmail.com this is also got failed so by passing indices parameter we can also specify specific data so which data you want to pass to the test method that
49:36
Speaker A
also we can control and not only two we can put multiple also so I can pass first one zero and also I want to pass one valid data so what's the index of this 0 1 2 3 so I can pass 0 comma 3 comma four three
49:53
Speaker A
inputs zero three and four and third one is a valid one 0 3 and four three specific data I'm passing so this is my first one second which is passed now this is my third one third one is also again
50:22
Speaker A
invalid So based upon by using indexes option we can also pass whatever inputs you want to pass to the test method now we can see this it is taking zero which is got failed and taking this third one
50:36
Speaker A
which is passed and the last one is got failed okay so this is how we can work with the data provider methods data provider method so what is the purpose of data provider method which will create test data and also
50:53
Speaker A
return it to the test method and test method will receive the data data and execute multiple times depends upon the number of inputs provided by the data provider method and the data provider name should be unique okay so this name we should
51:10
Speaker A
not give to any other data provider me suppose tomorrow you created another data provider method like this and same name method name anyway should be different but the name of the data provider also should be different so I
51:23
Speaker A
say DP have given here you can provide dp1 something like range we cannot specify only the specific values we can specify the range we cannot specify indices representing the specific rows number row number we can specify but range we cannot
51:41
Speaker A
specify okay so everybody's clear so far everyone please confirm in the chart Box about data provider method this is a one type of parameterization through data provider we can achieve data driven testing and the framework I will show you the
52:00
Speaker A
combination of Excel file and data provider method how we can achieve the data driven testing so data provider names wherever you create data provider method names are different names should be different okay same data provider name you should
52:16
Speaker A
not give to another data provider method wherever you create because we will get all the data provider methods in one class and everywhere we can refer that throughout the project wherever you want you can report that so because we
52:30
Speaker A
creating all the data providers in one single class data provider names should be different so when I say dp1 dp2 dp3 I can give different names same name you cannot give okay it will give you the duplication fine so now let us move on
52:50
Speaker A
to the next type of parameterization which is also very important how to can pass parameters from XML file so normally how we are using XML file so far to run the test right if you want run single class or multiple classes we
53:07
Speaker A
use XML file XML file is considered as a suit so in the same XML file we can provide the data we can pass some parameters to the test at the runtime and this approach especially used for parallel testing we can execute
53:23
Speaker A
the same test case multiple times uh sorry you can execute the same test case on multiple browsers parall so that we will see how we can do this so this is a step by-step process listen very very carefully parallel testing using XML
53:44
Speaker A
file okay so first of all uh I will create one test case and then I will run through XML file so that is a prerequisite then we will see how we can make it happen parallel so I will create
53:58
Speaker A
new class okay so I will name it as param test and finish so in the param test uh I will create uh few things so here I will create same again I'm going to create one setup method first listen carefully
54:18
Speaker A
so if you have any questions I will take it later so void setup okay and this method I will execute before class only once so I can make it as a before class and in the setup method is taking
54:32
Speaker A
care of launching the browser application and so on later I will implement the code and then I will write another actual test so I can say vo test logo one more test method this is one test method so this is my test annotation
54:51
Speaker A
also if you want I can give priority priority equal to one so that I can create multiple test methods I will implement this code later and another method I'm going to create void test title logo and title test this
55:08
Speaker A
is another test for testing the title and then here I can say priority equal to two so one is for testing the logo another test is for testing the title of the homepage and also I will write another
55:24
Speaker A
test for testing the URL of the page so I can write another test wi test URL test URL so this is another test test priority equal to 3 so now totally one method is executing before class three test methods and
55:48
Speaker A
finally I will create tier down so this will close my browser and everything so this I will execute after class so this I will execute after class okay so let's try to implement this code so in the setup for every method driver
56:06
Speaker A
is required so I create driver as web driver driver so at the time of implementation I'll try to use only Chrome browser and later we will add another browser so I'm creating a driver in the setup method driver equal to I say Chrome driver
56:27
Speaker A
let say Chrome driver and this will launch my browser Chrome driver so as soon as it is launched uh the browser then immediately I will try to launch my application also driver. getet and here you can pass any type of
56:44
Speaker A
application so I can just pass okay so this is a page I'm going to launch and if you you want to put implicit weight here itself you can put primmer do d. manage dot timeouts do implicitly waight duration dot of seconds so 10
57:10
Speaker A
seconds okay so this setup method is responsible for what launching the browser launching the application URL that's it now come to the logo so in that particular page I want to verify this logo is present or not so for that
57:26
Speaker A
I'm creating some piece of code so this is a way I'm capturing the logo element which is status and I put one assertion as. aset equals here I'm getting status true or false that I will compare with the true right if the
57:42
Speaker A
status is true both are matched so my test method will pass or else it will fail similarly test title so if you want to verify the title also I can put one validation Point here Tex title so here I'm directly
57:59
Speaker A
getting the driver. getet title that I'm comparing with the actual title expected title so this will return the actual title of the page that I'm comparing with our expected title so both directly I put in the assertion instead of storing the title
58:14
Speaker A
in another variable and put that variable here directly I provided this command driver dot get title and compare with our expected title and if both are equal then the has will make my test method pass if both are not equal my
58:29
Speaker A
test method will fail similarly test URL also I directly specify test URL so whatever URL we passed here the same URL should display here and how to capture the URL of the page which command driver dot get current
58:54
Speaker A
URL driver do get current URL so this URL will compare with our expected URL so this is another validation so three validations logo presence title and URL so three validations I'm doing and finally here I can say driver
59:14
Speaker A
dot driver Dot close or quit okay so we have implemented everything so let us try to execute this test run as test test so as of now this test is got created only for Chrome browser let me run one more
59:37
Speaker A
time so as of now this test is got created only for Chrome browser so logo is failed why because we haven't maximized the page let's maximize it driver Dot manage dot window do maximize okay so let me execute run as
60:07
Speaker A
test NG test is still logo is failing okay so we'll see the xath is correct or not okay so I guess exper is correct okay we'll do one thing so here we'll also put thread do sleep 3 seconds
61:06
Speaker A
okay so now all three got passed so all three got passed so now my test is perfectly working so the question is why we have not written true in s equals where can you tell me line number which line
61:29
Speaker A
38 okay so here we are using asset equals right asset equals method will compare two values and those two values Can Be Strings those two values can be Boolean those two values can be number anything right so driver. get title will
61:44
Speaker A
return which type of data string and here we specify the string so both will compare by the asset equals so that's the reason here we don't need to put true or false because here the asset equals method is comparing two string
62:00
Speaker A
values and here also same thing here asset equals is Method comparing two strings this will also return return the string this is also string so both will return string but here asset equals method compared to Boolean values why
62:14
Speaker A
because each displayed method is returning a Boolean value true or false so that's the reason I put true here so status value can be true or false and I put X true here if both are true then this method will pass if both are not
62:28
Speaker A
true or if one is true another and one is false then this will fail okay so it is not mandatory to put only Boolean values asset equals method will accept all kinds of data so here we are comparing two booleans here we are
62:43
Speaker A
comparing two strings here also we comparing two strings okay so now all three methods are passing now we'll see the next level we'll go to the next level so as of now this Butler test param test contains one
62:58
Speaker A
setup method three test methods one after class method so everything is executing only one browser that is Chrome browser okay so now what I want to do is my requirement is setup method is responsible for launching the browser right setup method
63:16
Speaker A
is a responsible for launching the browser which type of browser it is launching Chrome browser is launching now let me run this test through XML file okay so let me create an XML file to run this particular test so I'm
63:31
Speaker A
automatically creating this go to test NG convert to test NG and browse ITC test Java and day 45 okay now I have created one test.xml so if you run this XML file by default our test will execute right so let me
64:01
Speaker A
run this XML file okay now so I have executed my test the entire class using XML file so now First Step so what we have done we created test cases and second step created XML file to run the to run the test
64:41
Speaker A
case okay now the main thing will start so in the test case if I go back to the test case in the setup method we are launching the Chrome browser and some application URL right but now my requirement is I want to pass the
64:58
Speaker A
browser name from the XML file okay I want to pass browser name from the XML file so whichever browser name I passed my setup method should launch that particular browser for example when I pass Chrome here from XML file my setup
65:18
Speaker A
method should launch my Chrome browser when I pass Edge edge browser from the XML file my setup method should launch edge browser that means I'm going to pass a parameter from the XML file that I want to receive inside the setup
65:35
Speaker A
method you can receive in any of these methods but where exactly it is required in the setup method is required because browser name we are passing so we'll see how to pass browser name parameter from the XML file then we will see how setup
65:50
Speaker A
method will receive that parameter at the run time very very important so to pass parameter from the XML file inside the classes before classes started so we need to pass one thing called parameter tag so we need to add one tag called
66:08
Speaker A
parameter okay this is the additional tag where we have to specify this before classes parameter name equal to browser parameter name equal to browser that you need to put in the single port parameter is a browser and what is the value of this
66:28
Speaker A
browser value equal to Chrome and then close this classes parameter so what exactly we have done is before starting the classes we added one more tag called parameter and two attributes will be there name parameter so name attribute value attribute so
66:49
Speaker A
name attribute is a browser and the value of the browser is what Chrome okay name is is one attribute value is another attribute name attribute is value is what browser and the browser value is what Chrome so these are the two par these are the two
67:05
Speaker A
attributes we have to specify so that we are passing Chrome as a parameter so the browser is what Chrome here the parameter we can consider this as a variable and this is the value of the variable okay browser is a variable
67:20
Speaker A
Chrome is a value of the browser variable so this is how we can pass parameter from the XML file now now but how the setup method will receive that parameter from XML file there should be some mechanism right so setup method
67:34
Speaker A
should know from where I should take the parameter for that what we need to do is in the setup method you can put here also we need to put one more type of annotation at the rate parameters parameter annotation this
67:52
Speaker A
parameter annotation also we need to import from uh org. test. annotations and you can put before class after the parameters or before parameters no problem so these two also we can interchange no issues so we need to additionally add one theate parameters
68:09
Speaker A
annotation in this we have to specify in the first curly braas in the F in the curly brace we have to specify what is the name of the parameter is browser the same we have to specify here in the double quotes browser
68:26
Speaker A
okay now here we are passing browser parameter so here we need to specify the same variable name whatever variable name we have specified same name you have to specify here okay then whatever the value we are passing as part of the
68:40
Speaker A
browser our setup method will receive that in a variable so here we'll prepare one string parameter let's say BR okay now we are passing parameter from the XML file and set setup method will receive the browser value which is
69:00
Speaker A
Chrome into this variable because we specify the variable here so whatever value we have assigned to the browser this value will be captured into this variable BR okay this is a process so whichever parameter name we specified here the
69:19
Speaker A
same name you have to pass then what will happen whatever value has assigned to this variable the same value will be assign to the method VAR you can also pass multiple parameters that I will show you first we
69:33
Speaker A
will see for one parameter okay now once you get a parameter BR based on this parameter we have to decide which browser we want to launch okay sometimes I will pass Chrome here sometimes I will pass Edge sometimes I will pass Firefox whichever
69:50
Speaker A
browser you want you can pass but accordingly we have to launch our browser but as of now our script is launching only Chrome driver Chrome browser right but we need to modify this what you need to modify keep this code one side and this we have
70:05
Speaker A
to decide based on the parameter which we are receiving here so we will put one switch G statement here switch BR okay and this statement we have to execute when we have to execute this statement if the BR value is equal to
70:22
Speaker A
Chrome then only we have to execute the statement right so here I will put one case case BR sorry Case Chrome this is the way we need to do it okay so if the BR value is equal to
70:39
Speaker A
Chrome then do this launch our Chrome browser okay and then break suppose if my BR value is equal to Edge then what we should do driver equal to new edge browser Edge driver we are to launch and then
71:04
Speaker A
break so Edge driver we have to import suppose the browser name is equal to Firefox browser name is equal to Firefox so then I should launch driver equal to new Firefox driver and then break okay so I can specify whatever browsers
71:30
Speaker A
I have in your system suppose if this browser name is invalid suppose I pass some invalid browser name or some other browser name other than these three so then what we should do default block will execute so in the default block we
71:45
Speaker A
specify some message system. println invalid browser invalid browser and uh after that rest of the statements will as well execute right so our switch case block will decide which browser will be launched based on the parameter value okay suppose if the Chrome browser is
72:08
Speaker A
launched then rest of the code will be executed on the Chrome browser all the test will also execute on the same Chrome browser suppose if the switch switch case is decided edge browser then rest of the code will be executed on the
72:20
Speaker A
edge browser so the whole thing will be decided by the switch case statement now there is a problem in this for example if I pass some invalid browser so all three not matching then what will happen in the default block system. print
72:37
Speaker A
invalid browser it will say invalid browser perfectly fine then what will happen rest of the code will execute right but here it needs driver and rest of the test also will execute everywhere the driver is needed so if you're
72:51
Speaker A
passing invalid browser it is not possible to create the browser right so we should not execute the rest of the statements so if you're passing invalid browser immediately use one keyword called return return so what is the return keyword will do is the return
73:11
Speaker A
keyword will completely exit from this test it will exit completely exit from the not only switch case block the break command will just exit from only switch block but rest of the code will execute but what the return will do
73:27
Speaker A
return will exit from the entire method complete method so the rest of the code will not be executed so if the browser value is valid then only it will create a browser and rest of the code will be
73:41
Speaker A
executed if the browser is invalid then we are returning it means we are exiting from the entire method so this is something new you have to remember earlier we haven't discussed this okay so now what we have done
73:58
Speaker A
here BR is a variable just a variable which will store the browser name passed through XML file so from the XML file we are passing the Chrome right so that we are storing in the BR and if the BR
74:12
Speaker A
value is equal to Chrome then launching the Chrome browser if the BR value is equal to Edge then launching the Ed driver if a br value is equal to Firefox they're launching the Firefox driver if the BR value is equal to something else
74:26
Speaker A
we are saying the invalid browser and exit from the code okay till here everybody's clear so we are passing the parameter browser name from the XML file we are receiving here based on that we are launching the browser okay so this is a step number
74:47
Speaker A
two so past browser name parameter parameter from XML file and received in setup method so this is the third step so pass the browser name browser name parameter from XML file and received in the setup method so setup method why setup method is
75:19
Speaker A
received why can't other test methods can receive other test meths also can receive but the setup method is responsible for launching the browser right that is the reason we are receiving this parameter inside the setup method okay now let us test this
75:35
Speaker A
code so for now I'm passing the Chrome browser okay okay so okay for example uh yeah sometimes you may pass this in the lowercase character uppercase character in that case this will not match right if you pass in uppercase character so
75:54
Speaker A
this will not match or if you pass suppose here you are comparing upper case but here it is passing lower case then it will not match So to avoid that case sensitivity what I will do is I will convert this entire beay into lower
76:08
Speaker A
case Okay so obviously everything is a lower case definitely it will match even though if you pass an uppercase character here from XML files here it will convert into the lower case and match will happen no problem so you can
76:22
Speaker A
pass this value either uppercase characters or lowercase character characters now let me run XML file so now our test case is totally depends on XML file yes or no our test cases totally depends on XML file because our
76:36
Speaker A
setup method required our browser without browser parameter it cannot launch any browser right so can we run the test case alone without XML file can we run test case alone without XML file no if you run this what will happen
76:54
Speaker A
observe I'm running the test case without having XML file I'm directly running the test earlier we have run it but this time it will give you an exception what is an exception parameter browser is required by before class
77:07
Speaker A
method setup but it has been taken optional or defined what it is clearly saying to execute the setup method browser parameter is required that you are not getting why because we are not run through XML file okay so now the
77:24
Speaker A
test case entire test case is depends on XML file only through XML file we have to run the test case now I'm passing Chrome browser here let's run it run as test engine suit so as our as our expectation it
77:40
Speaker A
will launch my Chrome browser this is my Chrome browser then all test will be executed on the Chrome browser and it has got closed so the socket exception comes from this close let me use quit command so go to XML once
78:03
Speaker A
again so as of now it is launching my Chrome browser and all the test will be executed on the Chrome browser perfectly fine so all three test got executed and Chrome browser now let me change the another browser see instead of chrome I will
78:24
Speaker A
pass Edge okay so I'll pass edge browser so it should launch my edge browser then so let me execute my XML file once again so this time I'm passing Edge so this is my edge browser and executing all the tests on
78:54
Speaker A
my edge browser and perfectly pass so it is launched my edge browser perfectly fine so let us pass another browser ffox so I never prefer Firefox because it is very very slow browser so most of the times test cases
79:11
Speaker A
will fail because of unstability so most of the times prefer to use either Chrome browser or edge browser Safari is also fine if you're working on Mac so I've saved Firefox here but I don't have Firefox browser on my system I
79:33
Speaker A
guess do we have this okay it is automatically created see it is launched my Firefox this is my Firefox browser done so perfectly fine right so whichever parameter I'm passing whichever browser I'm passing my tests are executing on that particular browser
79:57
Speaker A
so with this what we have achieved cross browser testing we have achieved the same test case we are able to execute on multiple browsers just by passing the parameter just by passing the parameter now let's go to the next step
80:14
Speaker A
Next Level whenever I want to run my test on specific browser I'm passing the parameter when I pass Chrome my test is executing on the Chrome browser when I pass Edge my test is executing on the edge browser and so on so my
80:30
Speaker A
requirement is I don't want to pass this parameter every time okay but I want to execute my test on three browsers one after another I don't I don't want to change this parameter manually I don't want to change this parameter every time Chrome
80:48
Speaker A
ede Firefox I don't want to write this every time but still I want to execute my test case on Chrome browser then it will exit browser and and then firks one after another it should automatically execute sequentially then how we can
81:00
Speaker A
make it happen manually I don't want to change this parameter every time so then what you can do is you can create one more test entry okay so this is one thing this is one test entry right this
81:14
Speaker A
will execute on the Chrome browser now I can make another test entry two more entries and here I can pass edge browser here I can pass Firefox browser okay because I have created three tests the test name should be
81:34
Speaker A
different so here I'm changing the name I'll name it as a chrome test and here I will name it as a ed test and here I will name it as a Firefox test okay now I made three entries three
81:53
Speaker A
test entries so here this will execute on the Chrome browser this will execute on the test edge browser this will execute on the Firefox browser so one test we are executing one class we are executing on three different browsers by
82:06
Speaker A
creating multiple test entries okay now let us run the XML file I'm not changing anything just I'm running the XML file run as test so this is sequential execution so one after another first Chrome browser once it is completed then it will launch
82:27
Speaker A
edge browser so now it is completed then it is launched my edge browser and once it is completed then it will launch Firefox browser so Firefox is always slow I don't recommend to use so this is my Firefox
82:44
Speaker A
browser so now we are able to achieve the sequential execution sequential execution if you look at the test sort execution part see here first Chrome browser is executed all three test methods on edge browser three test methods are executed on Firefox again
83:02
Speaker A
three test methods are executed perfectly fine right so this is called sequential execution so in the fourth steps what we have achieved I will create all the steps one by one so in the fourth step execute the test case on Chrome
83:22
Speaker A
Edge and Firefox so Chrome comma Edge comma fbox I'm taking two uh three browsers Chrome Edge and five Fox this is called serial execution step number four executed our test case on Chrome Firefox and edge browser this is
84:03
Speaker A
sequential or we can say serial execution serial execution okay so far everything is clear so first we have created a new test case and run through XML file then we pass browser parameter URL also we can pass I will show you later so we
84:23
Speaker A
have passed browser name from XML file to setup method then we have executed the test case on three browsers in the serial execution or which is a sequential execution so sequential execution is nothing we just make another entry of the test so earlier we
84:39
Speaker A
have only one test entry in the XML file we make another two entries and we just change the browser name here Chrome here it is edge here it is a Firefox just we change the browser so first time this
84:52
Speaker A
will execute on the Chrome browser second time the same test will execute on the edge browser third time same test will be executed on the Firefox browser okay and when you create a multiple test the test name attribute
85:06
Speaker A
should not be same so that's the reason I have changed it here I say Chrome test here I say Edge test here I say Firefox test that's it so far every Everything Is Clear how we can achieve the serial
85:19
Speaker A
execution on multiple browsers cross browser testing with serial execution we have achieved yes so multiple test tags are needed if you want to execute the test on multiple browsers okay if you want to execute the test on multiple
85:38
Speaker A
browsers without changing parameter manually earlier we have changed the parameter I put Chrome first then I put Edge then I put Firefox instead of changing this parameter every time I can make another two entries and here I can
85:51
Speaker A
say Chrome here I can say AG here I can say Firefox so three times the test method test will execute on three different browsers so this is a concept okay so multiple test tags are required to run test on multiple
86:07
Speaker A
browsers now let us achieve the parallel execution so now currently all three are executing in serial ways one after another now how we can make them as a parallel very simple what we need to do is in the suit level
86:25
Speaker A
all the tests are there right so test one test two test three so these three tests I want to execute parall all three tests I want to execute them parallel so what I should do is go to the suit level here you need to add
86:39
Speaker A
one parameter that is parallel parallel equal to T parallel equal to T So this parameter makes parallel execution so these three tests will be executed parallely so all three browsers will launch at the same time and test also will be executed at
87:02
Speaker A
the same time so this parameter will make our test parallel and one more important thing this parallel option we can also use at the test level also suppose in the test I have a multiple classes let's say I
87:18
Speaker A
have multiple classes like this now I want to execute all these classes parall then then you can specify this parallel test at the test level also but in this case you have to say classes okay so if I use parallel equal
87:36
Speaker A
to test then test will execute parallel but inside the test if I use parallel equal to classes then these classes will execute parallel everybody getting my point but most of the times we don't prefer to use parallel class
87:56
Speaker A
execution okay so we prefer to use only test will parallel why because when you run the classes parall if there is any dependency they will definitely fail if there is no dependency that's fine it will work and pass execute par but if
88:14
Speaker A
there is any dependency definitely will fail so most of the times we just avoid this point we say parallel only test only test we will execute parel okay this is one parameter and one more thing can you see the thread count here
88:31
Speaker A
thread count let I come to that point hold on thread count you can see right so what is a thread count is representing thread count for test is optional it's not mandatory I can remove here and I'll put this thread count at
88:49
Speaker A
suit level okay I'll put the thread count at the suit level and the test level I can just remove this now let us understand what is the thread count why it is required what is the number I can
89:02
Speaker A
specify so thread count is nothing but at the run time it will create multiple threads for example let me explain this concept this is basically related to Java threading concept which is implemented in the as part of test
89:18
Speaker A
engine so let me tell you simple example let's say I have a test one test two test three in my XML file three test entries I have in XML file okay when you run this XML file suppose I have some memory
89:35
Speaker A
by default XML file when you run XML file only one thread will be created that means one process will be created in the memory let's say this is called thread thread or we can call it a process okay now when I run them
89:50
Speaker A
sequentially one after another so first test one will execute in this thread and after completion then it will take another test after completion it will take another test so same thread will be used for multiple tests one after
90:05
Speaker A
another here there is no problem right so when you come to the parallel testing when you come to the parallel testing again I have a two test methods test three and test three if you have only one thread if you have only
90:20
Speaker A
one thread the problem is it will can hold only one process at a time it can execute only one test at the time so if you want to make them parall we have to also increase the number of
90:33
Speaker A
threads we should also increase the number of thread only if you have only one thread even though if you put parall equal test tag it will go to the sequential execution okay why because it will create only one thread by default
90:47
Speaker A
suppose if you create a two two threads thread count equal to two then what happens it will allocate two memory locations and T1 will execute here T2 will execute here parall suppose one of one of them is become free then another
91:01
Speaker A
one will occupy it that means if I have only one thread execution will be very slow if I have a multiple thread execution will be very fast okay so if you have thread count two two memory locations will be created
91:15
Speaker A
if if have thread count five five locations will be created okay suppose if you have created thread count three so T3 will be allocated here t T2 and T1 all three we can execute parall without any disruption okay but how much value we
91:32
Speaker A
need to spacefy how many threads are required officially 2 to 5 is enough okay maximum 2 to five so don't go beyond Five Below two is not necessary because by default thread count is one only if you remove the thread count value in XML
91:49
Speaker A
file by default it will take one so one is not necessary put at least two minimum two maximum five so if we have 50 cases or 100 test cases still two to five are enough maximum five are enough
92:05
Speaker A
but if you increase more than five can we increase yes you can increase it but you will find some side effects so what are the side effects if you have suppose 100 test cases you are running pad you created 10
92:21
Speaker A
threads so if you keep on increasing the number of thread this will automatically reduce the performance of your code reducing the performance is nothing but what whatever memory you have in your computer it will take a lot of memory it will occupy lot
92:39
Speaker A
of memory as soon as increasing the number of threads this will automatically occupying a lot of memory other side so obviously that will also causing the performance poorness so that is the reason we should not go beyond five five is a acceptable okay so 2 to
92:58
Speaker A
five if you have just five to 10 test cases two is more than enough two is more than enough if you have 50 or 100 test cases then up to five you can go but don't go beyond five okay if you go beyond by again you
93:11
Speaker A
will face some unstability issues because of memory slow down performance will be reduced so you can find some unstability issues the test cases will fail frequently even if you increase a more threat count so it should the moderate value between 2 to five you
93:27
Speaker A
understood what is a thread count why it is needed so basically we are giving another some extra locations to run our test if you have only one test no need of thread con but if you have multiple test that two when you run parallely
93:43
Speaker A
definitely we have to specify the thread count so whenever you do parallel testing definitely we have to specify the red count yes basically we can a number of locations or number of processes or number of threads we can
94:00
Speaker A
say instance is a different word which we should not use it here okay so instance in that sense duplication here we are not running any duplicates test one is different test two is different test three is different so all three we
94:14
Speaker A
are running in the corresponding memory locations so I can say thread count equal to five or you can two or whatever you want so parallel equal to test when I add this parameter in the suit level then all test will be executed
94:29
Speaker A
parall but still there is a difference in fraction of seconds that we cannot notice okay there is some difference in the fraction of seconds because if you have n number of let's say if you have 150 test cases you will see lot of
94:44
Speaker A
difference so what is an advantage of running test parall do you have any advantage serial execution parall execution any advantage which we have when you run test through parallel execution any advantage why we need to go with parallel testing why it is
95:02
Speaker A
needed yes it will reduce lot of time for example I have test one test two test three test one take let's say 2 seconds of time test two take another two seconds of time test three take another two seconds of time if I execute
95:15
Speaker A
them serially how much of time it is taken totally 6 seconds right if execute them parall then what happens T1 and 2 2 2 three so it will take two two two the same parall way so ultimately within 2 seconds we
95:29
Speaker A
are able to finish all the execution it is very faster reducing the time so you will notice this difference time only if you have a more number of test case if you have 50 to 100 test cases you can
95:42
Speaker A
see lot of difference it reduce a good amount of time but if you have just two three five test cases you won't see much difference between serial execution and parallel execution okay so remember this so let's try to run it and see whether it is
95:58
Speaker A
running parallely or not so we already added the parallel equal to test let's try to execute run as and it will go very faster so we cannot see all five three instances parall so what I will do is I will increase this time out as a 5
96:16
Speaker A
seconds so that we can see all three browsers parallel execution at one shot so let me run as test Eng s Firefox will slowly loaded so but rest of them will go parall so this is one browser this is another browser
96:34
Speaker A
sorry this is another browser and now this is another browser three browsers launched parall but Firefox is obviously execution is very very slow so it will complete execution little bit slow now we can see the execution wise first edge
96:51
Speaker A
browser is got executed so it will take randomly okay sometimes it will take edge browser first sometimes it will take Chrome browser sometimes it will take Firefox it depends upon the speed and availability of the memory so all
97:05
Speaker A
three tests are got executed parallely so we can see Edge test Chrome test Firefox all three got executed so let me run one more time run as test Eng all three browsers at a time you can see so this is one browser this is
97:23
Speaker A
another browser see two browsers and this is third browser see one is Firefox one is Chrome one is hge so Firefox uh Edge Edge Chrome completed very faster but Edge is uh Firefox is little bit slow okay but all
97:42
Speaker A
of them parall loaded parallel execution is happened so this is how we can achieve the parallel testing if you remove this parameter sequentially execute serial execution will happen if I put this parameter parallel execution will happen Okay so everybody's understood so
98:03
Speaker A
the last point so after execution then we can make them parallel by adding one more parameter step number five execute test case on Chrome and Edge parallel execution same Firefox and if you do not have Firefox no problem you can leave it you can try
98:23
Speaker A
Chrome Ed browsers so step number one we created a new test case then we run through XML file just a normal execution and then we passed browser name parameter from XML file to setup method then we executed Chrome Firefox engage
98:39
Speaker A
in serial execution how we can execute serial execution by making multiple test entries now we executed the same on three different browser parallel execution is happened suppose if you want to pass some more parameters so as of now I'm passing only browser name as
98:54
Speaker A
a parameter here only browser name I'm passing suppose I want to pass the URL also application URL so then what you can do you can make another entry you can make another parameter like this and here the name is
99:12
Speaker A
I can say URL and the value you can put here and what is the whatever URL we are putting here the same URL I will pass from the okay and the same parameter I will pass for another test also so this is same
99:38
Speaker A
parameter I will add here order is not important suppose if you pass first URL then browser that is also fine so here I'm passing one parameter and here also I'm passing one more parameter URL and browser both are passing now we're
99:53
Speaker A
passing two parameters now we need to receive two parameters in the setup method browser comma URL and here also we need two parameters string URL and this URL we have to pass it here so instead of hardcoding this URL I'm just replacing
100:14
Speaker A
the URL that's it that is up to you okay your requirement if you want to pass URL you can pass it or else you you can ignore it no problem I just want to show you if you want to pass multiple parameters how
100:29
Speaker A
we can pass for that reason I'm taking URL is another parameter suppose you are doing login test you need username and password then you can pass username and password two parameter from the XML file like that okay so if you want to pass
100:42
Speaker A
two parameters you can just write a two parameters tax in the XML file here two parameters you need to specify and two variables also you need to specify and whatever URL I'm getting here that I'm replacing uh here okay here this URL is
100:59
Speaker A
actually coming from XML file earlier we have hardcoded the URL but this time we captured the URL from the XML file and put it here so let's go to XML file once again and then run it one more time so
101:13
Speaker A
this time we are taking browser name along with the URL also as a parameters so this is one browser this is another browser this is another browser totally three browsers are launched parall done so this time we also got a
101:37
Speaker A
URL as a parameter so multiple parameters also we can pass XML file through XML file by just adding multiple parameter TXS okay so everybody's understood now so if you don't want to pass URL you can don't pass just directly specifying
101:55
Speaker A
the test itself no need so it it decides based upon the test case how you have written the test case based upon your requirement you need to choose the parameters you need to decide how many parameters are required for the test can we pass from
102:13
Speaker A
the XML fall XML file or not so that you need to decide because as you said this is not necessary actually because for all the test URL is the same right URL is same but but browser is different I want to run
102:29
Speaker A
the same test on multiple browsers so I need to pass multiple browser names dynamically that is relevant but URL is same right if if you launch any type of browser URL is same right so it doesn't make any sense if I pass URL through XML
102:43
Speaker A
file but just I have shown you if you want to pass some other URL some other parameter how we can pass so for that I've have taken this example but actually URL is not much relevant so everybody's understood please confirm
102:58
Speaker A
in the chat box how we can do parallel testing using XML file which is very very very important concept again this will repeat in the framework Concept in the framework once we decide the framework then I will show you how we
103:13
Speaker A
can do data driven testing using data provid orientation with the combination of Excel sheet and also we will see how we can do the parallel testing how we can execute multiple test cases or multiple browsers and parall so we achieve cross browser
103:29
Speaker A
testing at the same time parallel execution so these are all Concepts so just try this and practice this today and tomorrow we'll discuss some more topics from test engine I will share all the files and do step by step okay directly don't jump to
103:49
Speaker A
the parallel execution first create a test case then run through XML file then pass browser name as parameter and see whether it's working properly or not and then do the serial execution by adding multiple test entries and then try to
104:03
Speaker A
run them parall so if you do step by- step practice you will you will not be confused everything will be more clear so don't directly copy paste my code you yourself do it first and if you block somewhere if I st somewhere then refer
104:17
Speaker A
my video and the example then continue with that all right so so that's all for today's session I will stop here and tomorrow we will continue
Topics:TestNGSeleniumJavaDataProviderParameterizationData-driven testingParallel testingXML parameterizationExcel dataTest automation

Frequently Asked Questions

What is the purpose of the DataProvider annotation in TestNG?

The DataProvider annotation in TestNG is used to supply test methods with multiple sets of data, enabling data-driven testing without writing explicit loops.

How does parameterization using XML files differ from DataProvider?

XML file parameterization is mainly used for parallel testing to run tests simultaneously on multiple browsers or environments, whereas DataProvider is used for data-driven testing with multiple data inputs.

Can test data be hardcoded in the DataProvider method?

Yes, for small data sets, test data can be hardcoded inside the DataProvider method. For larger data sets, it is better to read data from external sources like Excel files.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →