I have been spending the last 3 Months teaching myself Automated Testing. Having had no previous experience (manual tester who had never coded in my life) I have (with the help of this Board) managed to create a selenium Object Based Framework, written tests that link to this framework and got all my tests to run.
However I now need to take my test suite and pass it through multiple environments on a cloud based service. The problem I have is that I have to define the environment each time I run the test set. Ideally I want to be able to define the environments I run my tests on (Firefox, Chrome, IE etc), and then set the test suite off to run my set of 17 tests 3 times across each browser.
I Don't want to set up a system to run this locally but instead have a method that calls my different methods for my Cloud Service (currently trialling a couple)
a Sample of my code is as follows
Test Code - Login
namespace Kukd_Consumer_Test
{
[TestFixture]
public class Login : Consumer_Standard_Functionality
{
[Test]
public void User_Can_Login()
{
LoginPage.LoginAs("xxxxxxxxxx").WithPassword("xxxxxxx").Login();
Assert.IsTrue(AccountPageBtns.IsAtAccountPage("Hi Richard"), "Failed to login");
AccountPageBtns.Logout();
}
}
}
My standard Functionality (call driver go to homepage, quit etc) Currently I have to comment all but one of my Driver Methods. I want to be able to define multiples here Ideally so I can define which environments I run my tests on (locally or cloud based)
public class Consumer_Standard_Functionality
{
[SetUp]
public void Init()
{
// currently have to comment out all but the one I want to run.
driver.InitializeChrome();
//driver.InitializeFireFox();
//CBT_Driver.InitialiseChromeCBT(testName);
//CBT_Driver.InitialiseFFCBT(testName);
//CBT_Driver.InitialiseIECBT(testName);
//driver.InitialiseBrowserStack();
Homepage.GoTo_HomePage();
}
[TearDown]
public void Cleanup()
{
driver.Quit();
}
My local Driver Class (plus browserstack)
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using System;
namespace Kukd_Consumer_Tests
{
public class driver
{
public static IWebDriver Instance { get; set; }
public static void InitializeChrome()
{
Instance = new ChromeDriver(@"C:\Users\richard.cariven\Documents\Visual Studio 2015\Drivers\Chrome");
Instance.Manage().Window.Position = new System.Drawing.Point(2192, -963);
Instance.Manage().Window.Maximize();
Instance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
}
public static void InitializeFireFox()
{
Instance = new FirefoxDriver();
Instance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
}
public static string BSusername = "xxxxxxxxxxx";
public static string BSpassword = "xxxxxxxxxxx";
public static void InitialiseBrowserstack()
{
IWebDriver driver;
DesiredCapabilities caps = new DesiredCapabilities();
//caps.SetCapability("name", TestContext.TestName);
caps.SetCapability("browser", "IE");
caps.SetCapability("browser_version", "11.0");
caps.SetCapability("os", "Windows");
caps.SetCapability("os_version", "10");
caps.SetCapability("resolution", "1024x768");
caps.SetCapability("browserstack.user", BSusername);
caps.SetCapability("browserstack.key", BSpassword);
driver = new RemoteWebDriver
(new Uri("http://ift.tt/2dBBDcU"), caps);
Instance = driver;
}
public static void refresh()
{
Instance.Navigate().Refresh();
}
public static void Quit()
{
Instance.Quit();
}
}
}
CBT Class - Set up to pick each Cross Browser testing Parameter
namespace Kukd_Consumer_Tests
{
public class CBT_driver
{
public static IWebDriver Instance { get; set; }
public static string CBTusername = "xxxxxxxx";
public static string CBTpassword = "xxxxxxxxxx";
public static void InitialiseChromeCBT(string testName)
{
IWebDriver driver;
var caps = new DesiredCapabilities();
caps.SetCapability("name", testName);
caps.SetCapability("build", "1.0");
caps.SetCapability("browser_api_name", "Chrome56x64");
caps.SetCapability("os_api_name", "Win8");
caps.SetCapability("screen_resolution", "1366x768");
caps.SetCapability("record_video", "true");
caps.SetCapability("record_network", "true");
caps.SetCapability("username", CBTusername);
caps.SetCapability("password", CBTpassword);
driver = new RemoteWebDriver
(new Uri("http://ift.tt/2n1noAY"), caps);
Instance = driver;
}
public static void InitialiseFFCBT()
{
IWebDriver driver;
var caps = new DesiredCapabilities();
caps.SetCapability("name", "test name");
caps.SetCapability("build", "1.0");
caps.SetCapability("browser_api_name", "FF46x64");
caps.SetCapability("os_api_name", "Win8");
caps.SetCapability("screen_resolution", "1366x768");
caps.SetCapability("record_video", "true");
caps.SetCapability("record_network", "true");
caps.SetCapability("username", CBTusername);
caps.SetCapability("password", CBTpassword);
driver = new RemoteWebDriver
(new Uri("http://ift.tt/2n1noAY"), caps);
Instance = driver;
}
public static void InitialiseIECBT(string testName)
{
IWebDriver driver;
var caps = new DesiredCapabilities();
caps.SetCapability("name", testName);
caps.SetCapability("build", "1.0");
caps.SetCapability("browser_api_name", "IE10");
caps.SetCapability("os_api_name", "Win8");
caps.SetCapability("screen_resolution", "1366x768");
caps.SetCapability("record_video", "true");
caps.SetCapability("record_network", "true");
caps.SetCapability("username", CBTusername);
caps.SetCapability("password", CBTpassword);
driver = new RemoteWebDriver
(new Uri("http://ift.tt/2n1noAY"), caps);
Instance = driver;
}
}
}
So what I need to be able to do is, in my common test so it applies to every test, loop through each of my Browsers/CBT Environments for all tests.
Am currently set up using NUnit (changed from MSTest because I have read it is easier to do this kind of thing in NUnit)
Any advice greatly appreciated, I have been advised that because I have used so many statics in my tests this may not be possible.
Regards
Richard
Aucun commentaire:
Enregistrer un commentaire