Execution Of Test Cases In Sequential Order Using Selenium Webdriver - Part Two

In my previous article "Execution Of Test Cases In Sequential And Parallel Using Selenium Webdriver", we have learned the usage of Selenium webdriver, such as - it can be developed or used with different programming languages, and it also supports different platforms to execute its scripts or test cases. Selenium supports various drivers to execute its scripts based on its browser type, the various types of browsers it supports, and the configuration of hub and node etc..
 
And, we also saw the example of a sequential way of execution - how it executes the given script or test cases in seqential order which is defined by the programmer or developer.

In this article, we will see three different ways to execute our test cases or test method sequentially or in the given order which is defined by the programmer or a developer with its advantages and drawbacks.

Let's begin with our first example. In this article, we will use the same example which we used in our previous article, that is, "Execution Of Test Cases In Sequential And Parallel Using Selenium Webdriver".
 
Consider the scenario below. If I want to automate the Facebook application with the following steps.
  1. First, I want to register to a Facebook application.
  2. Then, I need to login to Facebook.
  3. Then, I want to create a post.
  4. In the fourth step, I want to update the content of the post.
  5. 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 without applying any sequential methodology, it is not executing in the given order; rather, it is executing in jumbled 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 test cases in sequential mode or sequential order, we need to make use of [ProcessTestFixture] and [TestSequence] attribute. To Execute test cases sequentially in the given selected order which is given by a programmer/ developer, we need to add Mbunit.Framework.dll in project's references.



In the below example, we will navigate to the Facebook application and we will automate the application by using Selenium Webdriver Script.

In order to automate its controls like firstname , surname , mobile name, email address, new password,  & so on from Register page of Facebook application, we use various control properties like its Control id, control name, XPath, className, cssSelector, Tagname etc.

If Control id, control name, className, cssSelector, Tagname are not available for n control, then we need to use an XPath. Each control will have a unique XPath to identify a control.
 
We need to use XPath property of a control in two different cases.
  1. When none of the control properties are defined.
  2. When the control properties are same for multiple controls. 
If there is any space in the className like "thumbnail-icon icon-state-saving", then we need to use cssSelector, wherever we find a single space in the class then we need to replace it with a dot(.) as well as in the beginning of the class and need to assign it to a cssSelector , if the spaces are not removed/replaced and assigned to className or cssSelector then it throws an exception.

Example

class="inputtext _58mg _5dba _2ph-" then we need to replace with dot(.) like cssSelector=".inputtext._58mg._5dba._2ph-" In order to find a control by its properties we need to inspect its element by right clicking on the webpage and selecting "inpect" if we are using  google chrome or inspect element if we are using Internet explorer.



EXAMPLE 1
  1. Using system;  
  2. Using Mbunit.Framework;  
  3. Using System.Threading;  
  4. Using OpenQA.Selenium;  
  5. Using OpenQA.Selenium.Chrome;  
  6. Using OpenQA.Selenium.IE;  
  7. Using OpenQA.Selenium.Firefox;  
  8. [ProcessTestFixture]  
  9. [TestClass]  
  10. public class TestClass {  
  11.     public TestClass {}  
  12.     [Test]  
  13.     [Mbunit.Framework.TestSequence(1)]  
  14.     public void RegisterToFacebook() {  
  15.             Iwebdriver driver = new ChromeDriver("D:/Drivers/Chromedriver/"); 
Here, we need to give the path of the chromdriver.exe if we want to automate the application in Chrome browser. Similarly, we can use various drivers like below.
  1. Iwebdriver driver=new InternetExplorerDriver("D:/Drivers/InternetExplorerDriver/");  
Here, we need to give the path of iedriver.exe if we want to automate the application in Internet Explorer browser.
  1. Iwebdriver driver=new FirefoxDriver("D:/Drivers/FirefoxDriver/");  
Here, we need to give the path of Geckodriver.exe if we want to automate the application in Firefox browser.
  1. Iwebdriver driver=new OperaDriver("D:/Drivers/OperaBrowserDriver/");  
Here, we need to give the path of operadriver.exe if we want to automate the application in Opera browser.
  1. driver.Navigate.GoToUrl("https://www.facebook.com/");  
As we are automating Facebook application, we are navigating to https://facebook.com.
  1. driver.Manage().Window.Maximize();  
  • This is used to maximize the browser.
  • In order to find a control, we are having FindElement method which is part of Iwebdriver class like below.
From the above image of registeration page , for the firstName control, we are having two control properties like name="firstname" and class="inputtext _58mg _5dba _2ph-". If either of these controls is not available, then we need to use an XPath.
  • For taking an XPath for a control, we need to write on the html element--> Navigate to Copy-->Copy XPath.



  • If we are using name properties, then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.Name("firstname"));    
  • In the className field class="inputtext _58mg _5dba _2ph-" , we are having spaces within the className property . If there are spaces, then we need to replace it with dot(.) as well as in the beginning of a class and needs to assign to CssSelector like below.
    1. IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));  
  • If we are using class properties with spaces in the class, then we need to use By.CssSelector() method.
    1. Element.SendKeys("Value you want to enter to firstname textbox");  
    2. Thread.Sleep(2000);  
  • This is used to wait for 2 seconds for every control which is being automated.
  • Inorder to automate the second control that is surname of registeration page we have control properties like name="lastname" and class="inputtext _58mg _5dba _2ph-"

     
    1. IwebElement Element = driver.FindElement(By.Name("lastname"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));  
  • If we are using class properties with spaces then we need to use By.CssSelecotor() method.
    1. Element.Sendkeys("value to enter to Surname field");  
  • Similarly for "Mobile number or email address" field we have control properties like name="reg_email__" and class="inputtext _58mg _5dba _2ph-"
    1. IwebElement Element = driver.FindElement(By.Name("reg_email__"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));  
  • If we are using class properties with spaces then we need to use By.CssSelector() method.
    1. Element.Sendkeys("value to enter to Mobile number or email address field text box");  
  • For "New Password" field we have control properties like name="reg_passwd__" and class="inputtext _58mg _5dba _2ph-"
    1. IwebElement Element = driver.FindElement(By.Name("reg_passwd__"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));  
  • If we are using class properties with spaces then we need to use By.CssSelecotor() method.
    1. Element.Sendkeys("value to enter to New password field text box");  
  • To Automate Birthday dropdowns like "Day Dropdown" we have class="_5dba" & name="birthday_day" ,id="day".
    1. IwebElement Element = driver.FindElement(By.Name("birthday_day"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.Class("_5dba"));  
  • Here we don't require CssSelector for class because we have only single value for class without any spaces.
    1. IwebElement dropdownvalue= Element.FindElement(By.Value("10"));  
    2. dropdownvalue.click();  
  • To Automate Birthday dropdowns like "Month Dropdown" we have class="_5dba" & name="birthday_month", id="month".
    1. IwebElement Element = driver.FindElement(By.Name("birthday_month"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.Class("_5dba"));  
  • Here we don't require CssSelector for class because we have only single value for class without any spaces.
    1. IwebElement dropdownvalue= Element.FindElement(By.Value("6"));  
    2. dropdownvalue.click();  
  • To Automate Birthday dropdowns like "Year Dropdown" we have class="_5dba" & name="birthday_year", id="year".

    IwebElement Element = driver.FindElement(By.Name("birthday_year"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.Class("_5dba"));
  • Here we don't require CssSelector for class because we have only single value for class without any spaces.
    1. IwebElement dropdownvalue= Element.FindElement(By.Value("2016"));  
    2. dropdownvalue.click();  
  • To Automate Gender Radio Button we have control properties / html element like
    1. <input type="radio" name="sex" value="2" id="u_0_i">  
    2. IwebElement Element = driver.FindElement(By.Name("sex"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.Id("u_0_i"));  
    2. Element.Click();  
  • For Create an Account button we have control properties like class="_6j mvm _6wk _6wl _58mi _3ma _6o _6v" name="websubmit" id="u_0_m"
    1. IwebElement Element = driver.FindElement(By.Name("websubmit"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.CssSelector("._6j mvm._6wk._6wl._58mi._3ma._6o._6v"));  
    1. IwebElement Element = driver.FindElement(By.Id("u_0_m"));  
    2. Element.Click();  
    3. }  
    4.    
    5. [Test]  
    6. [Mbunit.Framework.TestSequence(2)]  
    7. public void LoginToFB() {  
  • For Login Page of Username textbox we have various control properties like name="email" , class="inputtext" ,id="email" etc.
    1. IwebElement Element = driver.FindElement(By.Name("email"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.ClassName("inputtext"));  
    1. IwebElement Element = driver.FindElement(By.Id("email"));  
    2. Element.SendKeys("[email protected]");  
  • For Login Page of Username textbox we have various control properties like name="pass" , class="inputtext" ,id="pass" etc.
    1. IwebElement Element = driver.FindElement(By.Name("pass"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.ClassName("inputtext"));  
    1. IwebElement Element = driver.FindElement(By.Id("pass"));  
    2. Element.SendKeys("xxxxxxxxxxxxxx");  
    3. }   
    4. [Test]  
    5. [Mbunit.Framework.TestSequence(3)]  
    6. public void PostToFB() {  
  • To create a post on facebook application we have control properties like class="notranslate _5rpu"
    1. IwebElement Element = driver.FindElement(By.CssSelector(".notranslate._5rpu"));  
    2. Element.Sendkeys("Hello !! Good Morning To All My Facebook Friends...........!!");  
  • For post button of create post we have control properties like class="_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft".
    1. IwebElement Element = driver.FindElement(By.CssSelector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft"));  
    2. Element.Click();  
  • With this the given post will be posted on the tineline.
    1. }   
    2. [Test]  
    3. [Mbunit.Framework.TestSequence(4)]  
    4. public void UpdatePost() {  
  • For edit post button we have control properties like class="_54nc"
    1. IwebElement Element = driver.FindElement(By.ClassName("_54nc"));  
    2. Element.Click();  
  • To update the content in the textbox we have class property for textbox control like class="_1mwp navigationFocus _395 _1mwq _4c_p _5bu_ _34nd _21mu _5yk1"
    1. IwebElement Element = driver.FindElement(By.CssSelector("._1mwp.navigationFocus._395._1mwq._4c_p._5bu_._34nd._21mu._5yk1"));  
    2. Element.Senkeys("Hello !! Good Evening To All My Facebook Friends...........!!");  
  • For clicking Save button to update the post we have control properties like class="_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft"
    1. IwebElement Element = driver.FindElement(By.CssSelector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft"));  
    2. Element.Click();  
  • Click on Save button.
    1. }   
    2. [Test]  
    3. [Mbunit.Framework.TestSequence(5)]  
    4. public void DeletePost() {  
  • For Deleting a post we have control properties for Delete button like class="_54nc"
    1. IwebElement Element = driver.FindElement(By.ClassName("_54nc"));  
    2. Element.Click(); // It clicks on the delete button.  
    3. }  
    4. }  
  • When we execute the above project or test methods , it follows the sequence order which is given by the programmer / developer within the MbUnit.Framework.TestSequence() methods and executes the methods in the order like RegisterToFacebook(), LoginToFB(), PostToFB() , UpdatePost(), & DeletePost(). But the main drawback of using TestSequence() is that when we execute five different test methods we were supposed to get five different results.

    Suppose for the given five test methods, two are passed and three test methods are failed then we are getting only one result like passed. It is not showing the failed one's results.
  • From the above scenarios , if three are failed and two are passed then we gets passed count as one , and failed count as 0.

    The other drawback is that , while executing five different test methods , if any one of them fails in the middle , let's say third test case / test method failed then the other two that is 4th and 5th test methods are skipping.

    In order to overcome the above problem we have one more way to execute the test sequence in order by using DependsOnAtrribute which is part of MbUnit.dll

    Let's see the Next example

    EXAMPLE 2
    1. Using system;  
    2. Using Mbunit.Framework;  
    3. Using System.Threading ;  
    4. Using OpenQA.Selenium ;  
    5. Using OpenQA.Selenium.Chrome;  
    6. Using openQA.Selenium.IE;  
    7. Using openQA.Selenium.Firefox;   
    8. [TestFixture]  
    9. [TestClass]  
    10. public class TestClass {  
    11. public TestClass {}  
    12. [Test]  
    13. [Mbunit.Framework.DependsOnAttribute("")]  
    14. public void RegisterToFacebook() {  
    15. Iwebdriver driver=new ChromeDriver("D:/Drivers/Chromedriver/");  
  • Here we need to give the path of the chromdriver.exe , if we want to automate the application in chrome browser , Similarly we can use various drivers like below.
    1. Iwebdriver driver=new InternetExplorerDriver("D:/Drivers/InternetExplorerDriver/");  
  • Here we need to give the path of iedriver.exe , if we want to automate the application in Internet explorer browser.

    Iwebdriver driver=new FirefoxDriver("D:/Drivers/FirefoxDriver/");
  • Here we need to give the path of Geckodriver.exe , if we want to automate the application in Firefox browser.

    Iwebdriver driver=new OperaDriver("D:/Drivers/OperaBrowserDriver/");
  • Here we need to give the path of operadriver.exe , if we want to automate the application in opera browser.

    driver.Navigate.GoToUrl("https://www.facebook.com/");
  • As we are automating facebook application , we are navigating to https://facebook.com.

    driver.Manage().Window.Maximize();
  • This is used to maximize the browser.
  • In order to find an control we are having FindElement method which is part of Iwebdriver class like below.
  • From the above image , for the firstName control we are having two control properties like name="firstname" and class="inputtext _58mg _5dba _2ph-" , if either of these controls are not available then we need to use an XPath.
  • For taking an XPath for an control we need to right on the html element--> Navigate to Copy-->Copy XPath.

    IwebElement Element = driver.FindElement(By.Name("firstname"));
  • If we are using name properties then we need to use By.Name() method.
  • In the className field class="inputtext _58mg _5dba _2ph-" , we are having spaces within the className property . If there is spaces then we need to replace it with dot(.) as well as in the beginning of a class and needs to assign to CssSelector like below.

    IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));
  • If we are using class properties with spaces in the class then we need to use By.CssSelector() method.
    1. Element.SendKeys("Value you want to enter to firstname textbox");  
    2. Thread.Sleep(2000);  
  • This is used to wait for 2 seconds for every control which is being automated.
  • In order to automate the second control that is surname of registeration page we have control properties like name="lastname" and class="inputtext _58mg _5dba _2ph-"

    IwebElement Element = driver.FindElement(By.Name("lastname"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));
  • If we are using class properties with spaces then we need to use By.CssSelecotor() method.

    Element.Sendkeys("value to enter to Surname field");
  • Similarly for "Mobile number or email address" field we have control properties like name="reg_email__" and class="inputtext _58mg _5dba _2ph-"

    IwebElement Element = driver.FindElement(By.Name("reg_email__"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));
  • If we are using class properties with spaces then we need to use By.CssSelecotor() method.

    Element.Sendkeys("value to enter to Mobile number or email address field text box");
  • For "New Password" field we have control properties like name="reg_passwd__" and class="inputtext _58mg _5dba _2ph-"IwebElement Element = driver.FindElement(By.Name("reg_passwd__"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));
  • If we are using class properties with spaces then we need to use By.CssSelecotor() method.

    Element.Sendkeys("value to enter to New password field text box");
  • To Automate Birthday dropdowns like "Day Dropdown" we have class="_5dba" & name="birthday_day" ,id="day".

    IwebElement Element = driver.FindElement(By.Name("birthday_day"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.Class("_5dba"));
  • Here we don't require CssSelector for class because we have only single value for class without any spaces.
    1. IwebElement dropdownvalue= Element.FindElement(By.Value("10"));  
    2. dropdownvalue.click(); 
  • To Automate Birthday dropdowns like "Month Dropdown" we have class="_5dba" & name="birthday_month", id="month".

    IwebElement Element = driver.FindElement(By.Name("birthday_month"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.Class("_5dba"));
  • Here we don't require CssSelector for class because we have only single value for class without any spaces.
    1. IwebElement dropdownvalue= Element.FindElement(By.Value("6"));  
    2. dropdownvalue.click();  
  • To Automate Birthday dropdowns like "Year Dropdown" we have class="_5dba" & name="birthday_year", id="year".

    IwebElement Element = driver.FindElement(By.Name("birthday_year"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.Class("_5dba"));
  • Here we don't require CssSelector for class because we have only single value for class without any spaces.
    1. IwebElement dropdownvalue= Element.FindElement(By.Value("2016"));  
    2. dropdownvalue.click();  
  • To Automate Gender Radio Button we have control properties like / html element like
    1. <input type="radio" name="sex" value="2" id="u_0_i">  
    2. IwebElement Element = driver.FindElement(By.Name("sex"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.Id("u_0_i"));  
    2. Element.Click();  
  • For Create an Account button we have control properties like class="_6j mvm _6wk _6wl _58mi _3ma _6o _6v" name="websubmit" id="u_0_m"

    IwebElement Element = driver.FindElement(By.Name("websubmit"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.CssSelector("._6j mvm._6wk._6wl._58mi._3ma._6o._6v"));
    1. IwebElement Element = driver.FindElement(By.Id("u_0_m"));  
    2. Element.Click();  
    3. }   
    4. [Test]  
    5. [Mbunit.Framework.DependsOnAttribute("RegisterToFacebook()")]  
    6. public void LoginToFB() {  
  • For Login Page of Username textbox we have various control properties like name="email" , class="inputtext" ,id="email" etc.

    IwebElement Element = driver.FindElement(By.Name("email"));
  • If we are using name properties then we need to use By.Name() method.

    OR

    IwebElement Element = driver.FindElement(By.ClassName("inputtext"));

    OR
    1. IwebElement Element = driver.FindElement(By.Id("email"));  
    2. Element.SendKeys("[email protected]");  
  • For Login Page of Username textbox we have various control properties like name="pass" , class="inputtext" ,id="pass" etc.

    IwebElement Element = driver.FindElement(By.Name("pass"));
  • If we are using name properties then we need to use By.Name() method.

    OR

    IwebElement Element = driver.FindElement(By.ClassName("inputtext"));

    OR
    1. IwebElement Element = driver.FindElement(By.Id("pass"));  
    2. Element.SendKeys("xxxxxxxxxxxxxx");  
    3. }  
    4. [Test]  
    5. [Mbunit.Framework.DependsOnAttribute("LoginToFB()")]  
    6. public void PostToFB() {  
  • To create a post on facebook applications we have control properties like class="notranslate _5rpu"
    1. IwebElement Element = driver.FindElement(By.CssSelector(".notranslate._5rpu"));  
    2. Element.Sendkeys("Hello !! Good Morning To All My Facebook Friends...........!!");  
  • For post button of create post we have control properties like class="_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft".
    1. IwebElement Element = driver.FindElement(By.CssSelector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft"));  
    2. Element.Click(); // With this the given post will be posted on the timeline.  
    3. }  
    4.    
    5. [Test]  
    6. [Mbunit.Framework.DependsOnAttribute("PostToFB()")]  
    7. public void UpdatePost() {  
  • For edit post button we have control properties like class="_54nc"
    1. IwebElement Element = driver.FindElement(By.ClassName("_54nc"));  
    2. Element.Click();  
  • To update the content in the textbox we have class property for textbox control like class="_1mwp navigationFocus _395 _1mwq _4c_p _5bu_ _34nd _21mu _5yk1"
    1. IwebElement Element = driver.FindElement(By.CssSelector("._1mwp.navigationFocus._395._1mwq._4c_p._5bu_._34nd._21mu._5yk1"));  
    2. Element.Senkeys("Hello !! Good Evening To All My Facebook Friends...........!!");  
  • For clicking Save button to update the post we have control pproperties like class="_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft"
    1. IwebElement Element = driver.FindElement(By.CssSelector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft"));  
    2. Element.Click();  
  • Clicks on Save button.
    1. }   
    2. [Test]  
    3. [Mbunit.Framework.DependsOnAttribute("UpdatePost()")]  
    4. public void DeletePost() {  
  • For Deleting a post we have control properties for Delete button like class="_54nc"
    1. IwebElement Element = driver.FindElement(By.ClassName("_54nc"));  
    2. Element.Click(); // It clicks on the delete button.  
    3. }  
    4. }  
  • In the above example we have used [Mbunit.Framework.DependsOnAttribute("")] for all the test methods like,

    • For the first test method RegisterToFacebook(), as it is not dependent on other methods or test scripts we used attribute like [Mbunit.Framework.DependsOnAttribute("")] that is empty value with in the DependsOnAttribute methods.
    • For the second method that is LoginToFB() , as it depends on first test method that is RegisterToFacebook() , we need to define the attribute like [Mbunit.Framework.DependsOnAttribute("RegisterToFacebook()")]
    • For the third test method that is PostToFB() , as it is depending on the second test method that is LoginToFB() , we need to define the attribute like [Mbunit.Framework.DependsOnAttribute("LoginToFB()")]
    • For the fourth test method that is UpdatePost() , as it is depending on the third test method that is PostToFB() , we need to define the attribute like [Mbunit.Framework.DependsOnAttribute("PostToFB()")]
    • Similarly for fifth test method that is DeletePost() , as it is depending on the fourth method to be executed that is UpdatePost() , we need to define the attribute like [Mbunit.Framework.DependsOnAttribute("UpdatePost()")] & So on.
From the above example that is Example 2 , when we execute the above project or test methods , it executes in the specific order which we defined using DependsOnAttribute.

From the above five test methods if any two test methods are passed & three test methods are failed then we get the count for passed as two and failed as three , which is an advantage when compared to example 1 with TestSequence() attribute.
 
It also has the same drawback like TestSequence Example that is while executing the five test methods , if any one of the test methods failed , let's say second test method / test case failed then the remaining test methods like third , fourth and fifith are skipping.

In order to overcome the above drawbacks with MbUnit.Framework.TestSequence() and MbUnit.Framework.DependsOnAttribute() we have one more way of executing the test methods in the sequntial order that is
 
EXAMPLE 3
  1. Using system;  
  2. Using Mbunit.Framework;  
  3. Using System.Threading ;  
  4. Using OpenQA.Selenium ;  
  5. Using OpenQA.Selenium.Chrome ;  
  6. Using OpenQA.Selenium.IE ;  
  7. Using OpenQA.Selenium.Firefox ;   
  8. [TestFixture]  
  9. [TestClass]  
  10. public class TestClass {  
  11. public TestClass {}  
  12. [Test(Order=1)]  
  13. public void RegisterToFacebook() {  
  14. Iwebdriver driver=new ChromeDriver("D:/Drivers/Chromedriver/");  
  •  Here we need to give the path of the chromdriver.exe , if we want to automate the application in chrome browser , Similarly we can use various drivers like below.

    Iwebdriver driver=new InternetExplorerDriver("D:/Drivers/InternetExplorerDriver/");
  • Here we need to give the path of iedriver.exe , if we want to automate the application in Internet explorer browser.

    Iwebdriver driver=new FirefoxDriver("D:/Drivers/FirefoxDriver/");
  • Here we need to give the path of Geckodriver.exe , if we want to automate the application in Firefox browser.
    Iwebdriver driver=new OperaDriver("D:/Drivers/OperaBrowserDriver/");
  • Here we need to give the path of operadriver.exe , if we want to automate the application in opera browser.
    driver.Navigate.GoToUrl("https://www.facebook.com/");
  • As we are automating facebook application , we are navigating to https://facebook.com.
    driver.Manage().Window.Maximize();
  • This is used to maximize the browser.
  • In order to find an control we are having FindElement method which is part of Iwebdriver class like below.
  • From the above image , for the firstName control we are having two control properties like name="firstname" and class="inputtext _58mg _5dba _2ph-" , if either of these controls are not available then we need to use an XPath.

    For taking an XPath for an control we need to right on the html element--> Navigate to Copy-->Copy XPath.

    IwebElement Element = driver.FindElement(By.Name("firstname"));
  • If we are using name properties then we need to use By.Name() method.
  • In the className field class="inputtext _58mg _5dba _2ph-" , we are having spaces within the className property . If there is spaces then we need to replace it with dot(.) as well as in the beginning of a class and needs to assign to CssSelector like below.

    IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));
  • If we are using class properties with spaces in the class then we need to use By.CssSelector() method.
    1. Element.SendKeys("Value you want to enter to firstname textbox");  
    2. Thread.Sleep(2000);  
  • This is used to wait for 2 seconds for every control which is being automated.
  • Inorder to automate the second control that is surname of registeration page we have control properties like name="lastname" and class="inputtext _58mg _5dba _2ph-" IwebElement Element = driver.FindElement(By.Name("lastname"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));
  • If we are using class properties with spaces then we need to use By.CssSelecotor() method.

    Element.Sendkeys("value to enter to Surname field");

    Similarly for "Mobile number or email address" field we have control properties like name="reg_email__" and class="inputtext _58mg _5dba _2ph-" IwebElement Element = driver.FindElement(By.Name("reg_email__"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));
  • If we are using class properties with spaces then we need to use By.CssSelecotor() method.

    Element.Sendkeys("value to enter to Mobile number or email address field text box");
  • For "New Password" field we have control properties like name="reg_passwd__" and class="inputtext _58mg _5dba _2ph-"IwebElement Element = driver.FindElement(By.Name("reg_passwd__"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.CssSelector(".inputtext._58mg._5dba._2ph-"));
  • If we are using class properties with spaces then we need to use By.CssSelecotor() method.

    Element.Sendkeys("value to enter to New password field text box");
  • To Automate Birthday dropdowns like "Day Dropdown" we have class="_5dba" & name="birthday_day" ,id="day".

    IwebElement Element = driver.FindElement(By.Name("birthday_day"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.Class("_5dba"));
  • Here we don't require CssSelector for class because we have only single value for class without any spaces.
    1. IwebElement dropdownvalue= Element.FindElement(By.Value("10"));  
    2. dropdownvalue.click();  
  • To Automate Birthday dropdowns like "Month Dropdown" we have class="_5dba" & name="birthday_month", id="month".

    IwebElement Element = driver.FindElement(By.Name("birthday_month"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.Class("_5dba"));
  • Here we don't require CssSelector for class because we have only single value for class without any spaces.
    1. IwebElement dropdownvalue= Element.FindElement(By.Value("6"));  
    2. dropdownvalue.click();  
  • To Automate Birthday dropdowns like "Year Dropdown" we have class="_5dba" & name="birthday_year", id="year".

    IwebElement Element = driver.FindElement(By.Name("birthday_year"));
  • If we are using name properties then we need to use By.Name() method.

    IwebElement Element = driver.FindElement(By.Class("_5dba"));
  • Here we don't require CssSelector for class because we have only single value for class without any spaces.
    1. IwebElement dropdownvalue= Element.FindElement(By.Value("2016"));  
    2. dropdownvalue.click();  
  • To Automate Gender Radio Button we have control properties like / html element like
    1. <input type="radio" name="sex" value="2" id="u_0_i">  
    2. IwebElement Element = driver.FindElement(By.Name("sex")); //If we are using name properties then we need to use By.Name() method.  
    3. //OR  
    4. IwebElement Element = driver.FindElement(By.Id("u_0_i"));  
    5. Element.Click();  
  • For Create an Account button we have control properties like class="_6j mvm _6wk _6wl _58mi _3ma _6o _6v" name="websubmit" id="u_0_m" IwebElement Element = driver.FindElement(By.Name("websubmit"));
  • If we are using name properties then we need to use By.Name() method.
    1. //OR  
    2. IwebElement Element = driver.FindElement(By.CssSelector("._6j mvm._6wk._6wl._58mi._3ma._6o._6v"));  
    3. //OR  
    4. IwebElement Element = driver.FindElement(By.Id("u_0_m"));  
    5. Element.Click();  
    6. }   
    7.    
    8. [Test(Order=2)]  
    9. public void LoginToFB() {  
    10. //For Login Page of Username textbox we have various control properties like name="email" , class="inputtext" ,id="email" etc.  
    11. IwebElement Element = driver.FindElement(By.Name("email")); //If we are using name properties then we need to use By.Name() method.  
    12. //OR  
    13. IwebElement Element = driver.FindElement(By.ClassName("inputtext"));  
    14. //OR  
    15. IwebElement Element = driver.FindElement(By.Id("email"));  
    16. Element.SendKeys("[email protected]");  
  • For Login Page of Username textbox we have various control properties like name="pass" , class="inputtext" ,id="pass" etc.
    1. IwebElement Element = driver.FindElement(By.Name("pass"));  
  • If we are using name properties then we need to use By.Name() method.
    1. IwebElement Element = driver.FindElement(By.ClassName("inputtext"));  
    1. IwebElement Element = driver.FindElement(By.Id("pass"));  
    2. Element.SendKeys("xxxxxxxxxxxxxx");  
    3. }  
    4.    
    5. [Test(Order=3)]  
    6. public void PostToFB() {  
  • To create a post on facebook applications we have control properties like class="notranslate _5rpu"
    1. IwebElement Element = driver.FindElement(By.CssSelector(".notranslate._5rpu"));  
    2. Element.Sendkeys("Hello !! Good Morning To All My Facebook Friends...........!!");  
  • For post button of create post we have control properties like class="_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft".
    1. IwebElement Element = driver.FindElement(By.CssSelector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft"));  
    2. Element.Click();  
  •  With this the given post will be posted on the timeline.
    1. }   
    2. [Test(Order=4)]  
    3. public void UpdatePost() {  
  • For edit post button we have control properties like class="_54nc"
    1. IwebElement Element = driver.FindElement(By.ClassName("_54nc"));  
    2. Element.Click();  
  • To update the content in the textbox we have class property for textbox control like class="_1mwp navigationFocus _395 _1mwq _4c_p _5bu_ _34nd _21mu _5yk1"
    1. IwebElement Element = driver.FindElement(By.CssSelector("._1mwp.navigationFocus._395._1mwq._4c_p._5bu_._34nd._21mu._5yk1"));  
    2. Element.Senkeys("Hello !! Good Evening To All My Facebook Friends...........!!");  
  • For clicking Save button to update the post we have control pproperties like class="_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft"
    1. IwebElement Element = driver.FindElement(By.CssSelector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft"));  
    2. Element.Click();  
  • Clicks on Save button.
    1. [Test(Order=5)]  
    2. public void DeletePost() { 
  • For Deleting a post we have control properties for Delete button like class="_54nc"
    1. IwebElement Element = driver.FindElement(By.ClassName("_54nc"));  
    2. Element.Click();  
  •  It clicks on the delete button. 
  • In the above example that is Example 3 , we have used Order Attribute which is an int type and a parameter of Test method attribute, we have defined [Test(Order=1)], [Test(Order=2)],[Test(Order=3)],[Test(Order=4)],[Test(Order=5)] and so on ,
When we execute the above project or test methods , it will execute in the order we specified for Order in the test parameter , in order to over come the above problems like by using TestSequence and DependsOnAttribute we were unable to proceed when one of the test method / test cases fails and we are not getting the individual count for passed and failed cases.
 
By using the Test(int Order) , when any one of the test cases or the test methods fail in the middle then also we were able to execute the remaining test cases.

And we also get the individual test case/test method report like passed count as 2 and failed count as 3 and so on. Thanks and I hope this helps you. Please provide me with feedback if I missed anything.

Up Next
    Ebook Download
    View all
    Learn
    View all