Selenium Grid - Cross-Browser Testing and Parallel Testing

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Welcome to our ADM Lucid automation testing Channel we'll have a series of talk about selenium automation testing which will help you understand the basics of selenium and also guide you to build your own selenium automation project you may access our test project and guide in the description below feel free to subscribe to our channel for any new videos and updates I hope you enjoy the video in today's video we will talk about this concept or this thing called selenium grid so first what is selenium grid so slim grid is a powerful tool for running selenium test in parallel on multiple different browsers and operating systems it is a part of the selenium suite and is designed to enable efficient and scalable testing of web applications across different environments so next I'll kind of cover some key aspects of selenium grid so the first is that grid allows parallel testing so what does that mean what it means is it allows you to distribute the test cases across multiple machines or nodes and run them in parallel so this will reduce the runtime uh and make it much more efficient to run test automation the next thing is selenium grid allows cross browser testing so with slim grid you can perform cross brow testing by configuring the different nodes that we had to run on different web browsers such as Chrome Firefox Safari or internet browser and this will ensure that your web application works correctly across the different browser environments the next thing is it lasts crossplatform testing and again this is because you can configure the nodes to work on different operating systems and this will help you identify platform specific issues and ensure that the compatibility is right with various different operating systems and also it allows scalability selenium grid is highly scalable you can add remove nodes dynamically as needed to accommodate changes in testing requirements or to handle increased testing loads uh the scalability makes it suitable for small and large test Suites configuration is also something of selenium grid so nodes in selenium grid are configured with desired browser and platform settings and these configurations you can customize depending on the needs for your uh testing application testing also remote web driver so selenium grid uses the remote web driver API and this allows test scripts to interact with browser instances running on remote machines and so the test script can be written in various different languages like Java python C and they can communicate with the Hub to initiate tests on nodes another property of selenium grid is load balancing so the Hub can distribute test cases to nodes in a balanced way ensuring that uh our testing workload is evenly distributed from with all our resources and this will further increase the optim or an optimize are testing uh there's also Hub and node registration and basically nodes need to register with the Hub to make themselves available for test execution and this registration process involves specifying the nodes cap uh capacity capabilities such as its browser type its version and its platform and there's also this Hub node architecture and slim grid and basically slim grid consists of two main components it's the Hub and the nodes we mentioned the Hub is basically the central server that manages all the different test distributions to the different nodes and the nodes are basically the individual machines that execute the selenium test so test scripts that we write directly communicate with the Hub which then directs them to appropriate nodes based on the browser and platform configurations we need so to look at this sort of architecture a little bit more I'm going to open this link and what they have is they have this sort of um sort of flowchart for to describe this and we see that basically as a client when we send our um when we send our requests for different tests to the router it will create a session queue and this session queue will basically first check if we already have a session with the same ID running and if so it'll send it directly to the node and if not it'll bring it to the distributor and the distributor will then distribute our processes to node also when we send our test scripts to the router what also happens is that it will create a session map and this will basically assign the different nodes and the different resources to this bank that will basically store it so in the future um we can basically but but yeah so if you're interested in like the more detailed version of this um feel free to visit this website right here um it gives gives you a pretty good uh sort of overview of this selenium grid architecture and also to download selum grid you can just go to their GitHub and in our little in our uh in our video today we used the selenium server 4.13 jar file we just downloaded it and we put it into the folder that we needed and to use selenium grid uh basically what we did uh was we uh created a grid Java class under the controller packages uh and then we imported the uh of course we imported um the package that we need to use so the remote web driver API that we mentioned earlier and then we also did this and basically right here uh we created an instance for the remote web driver and then we basically set um this new URL thing uh argument right here which is very important and uh if you wanted to start it as a standalone process then you would use this command here and this is for if you want to start a hub and node you would use this Command right here with the uh file downloaded from the GitHub and this is for nodes so the first one is for Hub the second one is for nodes and this is basically specifying the port that you want the node to be on default is 5555 and yeah next we're going to use selenium grid inside our code so we're just going to show you how we can do this and how we can use selenium grid inside our code so first I'm going to go to this grid uh grid class that I created under our controller package and you can see it's right here and we're going to have to first import two things the first is the URL and the second is the remote web driver and we talked about this earlier in our presentation we have to import both of these in order to use the selenium grid so next inside this class um it's mostly similar to the class we used before with a slum expectation but there are a few differences so the first thing is we have we created this method called test grid and inside this method we have this remote URL which is Local Host 4444 and you you'll see we use this remote URL later after that we have these basically um these different statements so first we create an instance for desired capabilities and then we set the browser name to Chrome we set the brow the platform to Windows 11 and then we create an instance a remote web driver instance with the remote URL and the capability instance that we created earlier and you see that in this one specific a little block of code here we are using Chrome uh and we're creating a Chrome web browser but we also have it for Firefox Edge Firefox Mac Firefox Linux and so on and we even have it for Safari as well and Below we just have some implicit weights so that um it hap what we want happens uh because we must wait for it to load for a bit before it happens so this is our test grid uh method next We have basically a page title URL method and some other methods as well just to test um the selenium expected conditions and in this URL um there are a few differences than before um if you don't remember what expected conditions are I suggest you uh go back to our video about selum expected conditions and watch that again but essentially we have some uh different expected conditions and we're just testing to see if the web page that we enter is uh getting the condition we get um and the key difference about this one is we're using this test grid browser and this allows us to use selenium grid to perform these expected conditions instead and you see in this one we're testing adm.com dglf and we have some different conditions for the title um for the URL and so on and so after we do that before we uh want to use slam grid we must uh first we'll check that we have Java installed our computer so we can enter this Java Das version command after we do that we're going to uh recall that we installed selenium server 4.13 earlier so we're going to actually run this using Java and we're going to use the command called Standalone and this basically means we're just running on our computer and we're going to go ahead and run it and basically it's going to load and it's going to give you a bunch of output um but a few things to note in output see it says detected 12 available processors um and basically um there's some other commands in here for example it says um added Edge 12 times added Chrome 12 times um added Firefox 12 times um and Internet Explorer uh one time and this will become a little bit more apparent later when we show you the uh graphical interface uh but yeah so you run this inside your command line and now you can start using selenium grid so we're going to run that and now what we can do is we can switch back to our ID and this time we're going to go to um we're going to go to our test package instead and under our test package we have a few different tests um we have app test uh grid for Chrome grid for Edge and grid for Firefox uh I'm just going to open grid for Chrome and this is what it looks like inside um it's basically essentially the same thing uh we just call upon the conditions uh we call upon the methods inside the uh the grid class and we uh we see if it runs so in order to run this I'm just going to rightclick the whole package uh folder uh test and I'm just going to run test and test so it pops up this window CU we're testing ADM lucid.com golf in this um method and it's just a bunch of test and you see it open the Chrome browser and it's opening another Chrome browser and it's opening Chrome browsers multiple times it opened Firefox it also opened Edge uh and yeah so it's open all those browsers and um it just finished running so um there's actually a goey interface that we can look at to monitor our test while it's running so we're going to open this uh Firefox browser uh and yeah just drag it over and uh this is what the selenium grid interface looks like and you see that the URL on top is Local Host 444 I'm just going to go ahead and go to overview and we see here this is the 12 Chrome that we're talking about earlier the 12 Firefox one Internet Explorer and 12 Edge that we mentioned earlier um when we use the standard loone command in our terminal and yeah it gives you some other commands like mac concurrency some other uh uh um some other configurations and stuff uh but yeah I'm I'm going to close that and now what I'm going to do is I am going to uh run this again so I can show you what it looks like here um and you see when we uh it pops up over it but I'm just going to go back and I'm going to show you here it shows you uh your session info um and it'll show you um how it's running and stuff um and this is a nice little graphical interface you can use to monitor your selenium grid uh while it's running and we'll give it some time to run and I think it finished running yeah I'm going to go ahead and check and yeah it's all done and yeah that's basically uh using selenium grid with the Standalone command so next I'm going to show you how we can utilize The Hub and the node uh architecture in selum Grid um because earlier we used the standard alone command and that was basically just running in your local computer but now what we want to do is we want to use the architecture we mentioned earlier in the PowerPoint so first you go back here you go back to your terminal and you're going to open uh you're going to use the Hub command instead um earlier we used stand alone this time you use Hub and basically this will create a hub to control all your notes and you see on the bottom line it says started selenium Hub 4.13 and that human basic says we we we started the Hub so now to add nodes we're going to add we're going to open another terminal make sure you don't uh close the earlier terminal and this time the command we're going to use is we're going to use the same thing except we're going to use the node argument and see here we use node and it's going to run and it's going to say node C has been added on the bottom uh and if we go back to our uh Local Host 4444 which is basically the URL we defined earlier you can see we have this one node here now I'm going to open another terminal so I'm going to open another terminal and I'm going to add another node so we're going to basically use the same command with node I'm going to press enter uh or actually remember um the default node has Port 5555 so this time I'm going to use port 6666 and oh I think I made a mistake with the argument so I'm going to re-enter uh you have to have two dashes for the port I only had one dash so two dashes 6666 and I'm going to add a node and it'll basically say node has been added nice and now the node has been added so you see in our uh interface graphical interface we have two nodes so I'm going to add one more notes I'm going to open another terminal and this time I'm going to use port uh 7777 and I'm going to run that and now we have added the node on the bottom because it says node has been added uh or I drag it up yeah now node has been added and uh yeah so we added three nodes so now we can go back to the go interface and we see that we have three nodes now so now if I go back to our code and I go back to our test and I run the test we'll see we we'll expect it to use all three nodes so we open up the graphical interface we see that uses the first node to run that part of the test and then it uses a second node to run another part of the test and then finally it will use the third node to run another part of the test and so it's basically alternating between the nodes to run portions of the test and once the test nodes are done running uh uh once the test are finished I think the test have now finished so uh yeah I'm going to go back to the um go back to IDE and uh yeah so the test finished and we Ed basically we alternated between the different nodes to finish the test but um sometimes we want to run in parallel so that we can use all our resources more efficiently so for instance if we want to run on all three nodes at the same time in order to do that you have to first install a plugin so you go to settings and then you go plugins and then you're going to install multi-run plugin so I already have it installed but you can go ahead and install that and then you can just press okay on the bottom and after you install that now you have to create your test classes a little bit differently according to the syntax requirements for multi-run so right here I have a YouTube uh package and I'm under it I have YouTube Chrome uh YouTube Edge and YouTube Firefox I'm just going to open uh one of them so right here I have YouTube Chrome open and we see here first we have to import some different packages so for uh test package also do execution package also a execution mode package as well and then on the top we use a tag at execution and execution mode concurrent and that's very important and each time we try to run a method within the uh the classes that we want to have that has the methods to test stuff we use an at test tag before the method and this will basically allow us to use multiun and use the nodes concurrently I'm just going to show you the YouTube one we used instead um this is essentially the same stuff um except this one is basically testing a different browser a different URL and we're just testing a YouTube channel so we're just opening our YouTube channel and then we're keeping it in the background um and you see that basically have the same stuff we have a test grid um method to Define um the test grid and use remote driver and then we have these tests which basically um open up this YouTube channel and then we wait for 120 seconds we let it run for 120 seconds and see if it works and then we quit so this is basically the uh the class uh that we have the controller class for YouTube and yeah so it's up here and now if we want to run these tests um we actually have to do something a little bit different so we actually have to go to run and then we have actually have to go to edit configurations and before we were using junit when we were running it alternately through the different nodes this time we have to go to the bottom so you see on the bottom there's multiun I'm going to click it and you can actually add your new configuration I already have a configuration here called parallel test but if you go back you can add new run uh new configuration there and here under this I added the three different classes that I want to run with and um I have YouTube Chrome YouTube Edge and YouTube Firefox and I can go ahead and press okay and now when I click run on the top I can select run parallel test which is the configuration I just mentioned earlier and I just created so I click that and now it should use all nodes concurrently so uh it opens up uh so we opened up Chrome one on our YouTube page opened up a edge browser on our uh YouTube page and if I go to our go interface you see it's using the second and third node uh at the same time and it's running it in parallel and you see we have multiple sessions running at the same time and this is basically using the SL grid architecture and yeah so this is basically how you can Implement and use selenium Grid in your own code um if you found this video helpful uh please give us a like And subscribe to our channel uh and stay tuned for any new videos uh thank you for listening
Info
Channel: Test Automation 101
Views: 4,553
Rating: undefined out of 5
Keywords: Selenium Grid, Distributed Testing, Parallel Test Execution, Selenium Grid Hub, Selenium Grid Node, Cross-Browser Testing, Parallel Testing with Selenium, Automated Testing Efficiency, Selenium Testing Framework, Web Application Testing, Testing Best Practices
Id: Z0GRob7lmb0
Channel Id: undefined
Length: 21min 4sec (1264 seconds)
Published: Fri Oct 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.