Advertisement
ken4ward

Selenium, C#, running multiple test cases

Jan 30th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using OpenQA.Selenium;
  4. using TestingProject.TestBase;
  5. using OpenQA.Selenium.Support.UI;
  6. using OpenQA.Selenium.IE;
  7. using TestingProject.TestConstant;
  8.  
  9. namespace TestingProject
  10. {
  11.  
  12.     //first class. the base class where the driver class is inherited
  13.     public class Layers : TestBase.TestBase
  14.     {
  15.         public Layers() { }
  16.         public Layers(IWebDriver driver) : base(driver){ }
  17.         public void LayerOne(String ExpectedElement)
  18.         {
  19.             driver.FindElement(By.CssSelector(ExpectedElement)).Click();
  20.         }
  21.     }
  22.  
  23.     //second class. This contains a method that passes parameter to force the driver to wait until the expected element is visible
  24.     public class Layers2Class : TestBase.TestBase
  25.     {
  26.         public Layers2Class() { }
  27.         public Layers2Class(IWebDriver driver) : base(driver) { }
  28.         public void FullElementPageLoad(String WaitPeriodParameter)
  29.         {
  30.             WebDriverWait tests = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
  31.             tests.Until(ExpectedConditions.ElementIsVisible(By.CssSelector(WaitPeriodParameter)));
  32.         }
  33.     }
  34.  
  35.     //combined class. This class has a method that passes parameters into the first 2 classes instantiated within it.
  36.     public class LayerCombined : TestBase.TestBase
  37.     {
  38.         public LayerCombined() { }
  39.         public LayerCombined(IWebDriver driver) : base(driver) { }
  40.         public void FullElementPageLoad(String WaitPeriod, String elementpresent)
  41.         {
  42.             new Layers2Class(driver).FullElementPageLoad(WaitPeriod);
  43.             new Layers(driver).LayerOne(elementpresent);
  44.         }
  45.     }
  46.  
  47.    //This is class in which the actual expected parameters are passed into the first 2 classes.
  48.     public class LayerParam : TestBase.TestBase
  49.     {
  50.         public LayerParam() { }
  51.         public LayerParam(IWebDriver driver) : base(driver) { }
  52.         public void CollectParam()
  53.         {
  54.             LayerCombined LayerCombined = new LayerCombined(driver);
  55.             LayerCombined.FullElementPageLoad("#content > div > div.col-xs-12.col-sm-12.col-md-7.col-lg-8.hidden-xs.hidden-sm > div.hero > img", "#btnSigin");
  56.         }
  57.     }
  58.  
  59.     //It is in this class in which the test is ran.    
  60.     [TestClass]
  61.     public class ClassRunner : TestBase.TestBase
  62.     {
  63.         public ClassRunner() { }
  64.         public ClassRunner(IWebDriver driver) : base(driver) { }
  65.  
  66.         [TestMethod]
  67.         public void RunAll()
  68.         {
  69.             driver = new InternetExplorerDriver();
  70.             driver.Navigate().GoToUrl("http://www.google.com");
  71.             new LayerParam(driver).CollectParam();  
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement