maxInstances=10 -Dwebdriver.firefor.driver="D:/drivers/Geckodriver/geckodriver.exe" -browser browsername="chrome" , version=ANY , platform=ANY , maxInstances=10 -
Dwebdriver.chrome.driver="D:/drivers/chromedriver/chromedriver.exe" -browser browsername="internet explorer" , version=ANY , platform=ANY , maxInstances=10 -
Dwebdriver.ie.driver="D:/drivers/InternetExplorerDriver/iedriver.exe"
-role -node- hub http://192.168.122.1:4444/grid/register : It is nothing but we are configuring an node either firefox , chrome , IE to the hub which has an IP address of
192.168.122.1 and with port no. 4444
maxInstances defines the number of instances of browsers we want to open. We need to define the path of the drivers which we installed into the drivers folder. Wemust provide the .exe path of the nodes based on which we are configuring.
In the above code, we configured 3 nodes that is Firefox, Chrome, & IE with their paths like,
- Dwebdriver.chrome.driver="path of chrome .exe"
- Dwebdriver.ie.driver="path of IE .exe"
- Dwebdriver.firefox.driver="path of Firefox .exe"
In the above commands, we configured 3 different nodes to a single hub. If there are multiple test cases to execute, then it is hub's responsibililty to divide or distribute the test cases among the 3 given nodes.
Using Selenium webdriver, we can execute test scripts or test cases either sequentially or parallely using gallio bundle which is a tool of selenium.
To execute test cases parallely, we need to use [TestFixture] & [parallelizable] attributes and maxinstances attribute. By default, the maxInstance attribute has a default value of 1, that means when we execute the testcase, hub opens only single browser at a time. If we define maxInstances=5 while configuring a node, then based on multiple test cases to execute, it opens 5 different browser instances to execute the given test cases.
If we set maxinstances=10 then we can open 10 different instances of chrome or Internet explorer or firefox etc simultaneously which helps us to execute the test cases in multiple instance browsers which reduces the manpower as well as we can reduce the time.
In selenium webdriver , we can execute the testcases either parallely or sequentially. In certain scenarios we were unable to automate the application based on the sequential order of the testcases. Consider certain scenario like below, If i want to automate the facebook application with the following steps.
- First i want to register to an facebook application.
- Then i Need to login to facebook.
- Then i want to post something.
- In the fourth step i want to Update the content of the post.
- In this step i want to delete the post.
From the above given scenarios , let us consider the above steps as TestMethods like RegisterToFacebook(), LoginToFB(), PostToFB() , UpdatePost(), & DeletePost() etc ,then when we execute them , it is not executing in the given order rather it executing in jumble order like
first it is trying to execute the DeletePost() method , but there is no post to delete it and hence we are getting failed result.
To execute testcases in sequential mode or sequential order then we need to make use of [ProcessTestFixture] and [TestSequence] attribute.
To Execute test cases in sequentially in the given selected order, we need to add Mbunit.Framework.dll in projects references.
- Using system;
- Using Mbunit.Framework;
- [ProcessTestFixture]
- public class TestClass {
- public TestClass {}
- [Test]
- [Mbunit.Framework.TestSequence(1)]
- public void TestMethod1() {
-
- }
- [Test]
- [Mbunit.Framework.TestSequence(2)]
- public void TestMethod2() {
-
- }
- [Test]
- [Mbunit.Framework.TestSequence(3)]
- public void TestMethod3() {
-
- }
- [Test]
- [Mbunit.Framework.TestSequence(4)]
- public void TestMethod4() {
-
- }
- [Test]
- [Mbunit.Framework.TestSequence(5)]
- public void TestMethod5() {
-
- }
- }
From the above code, for sequential order we need to replace the [TestFixture] attribute to [ProcessTestFixture] . If we don't replace it, then we will be getting same failed result because the above code will not be executing in the given order which we have provided.
When we execute the above project, we can execute it in the provided order because of TestSequence() method. This TestSequence() method accepts a parameter of type (int order). Here, we need to provide the order which we want them to execute. In this case, we get the pass result.
To Execute test cases parallely
In order to execute the test cases parallely, we need to add two different dll's to its project references that is,
which we can get from NuGet.
Given below is the program to understand the execution of test cases in parallel.
- using system;
- using mbunit;
- [assembly: DegreeOfParallelism(20)]
- [assembly: Parallelizable(TestScope.All)]
- [TestFixture][Parallelizable]
- public class Testclass {
- public Testclass() {}
- [Test][Parallelizable]
- public void TestMethod1() {
-
- }
- [Test][Parallelizable]
- public void TestMethod2() {
-
- }
- [Test][Parallelizable]
- public void TestMethod3() {
-
- }
- [Test][Parallelizable]
- public void TestMethod4() {
-
- }
- [Test][Parallelizable]
- public void TestMethod5() {
-
- }
- }
Thanks! I hope this helps you.