Showing posts with label Automation. Show all posts
Showing posts with label Automation. Show all posts

Monday, April 8, 2013

Running Selenium tests from Visual Studio – Step by step

From Firefox, record new selenium test, for example for Google search

2013-04-07_13-14-39

Export the test to C# web drive

2013-04-07_13-15-06

This is how it looks like after export

2013-04-07_13-15-50

Open visual studio, create new test project

2013-04-07_13-16-36

By default the file UnitTest1.cs is created

2013-04-07_13-25-47

Create a new cs file, name it for example GoogleSearch

2013-04-07_13-25-54

Copy the code from the cs file generated by selenium and paste it in the file GoogleSearch.cs

2013-04-07_13-26-42

Add reference in the project to Selenium .Net WebDriver, WebDriver.dll and WebDriver.Support.dl

2013-04-07_13-29-322013-04-07_13-29-07

Now the references added, you can see that the editor recognizes the selenium name spaces

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;

2013-04-07_13-29-40

Find and replace “TestFixture” to “TestClass”, “SetUp” to “TestInitialize()”, “Test” to “TestMethod”, “TearDown” to “TestCleanup()”

2013-04-08_00-31-32

To run with Chrome, download chromedriver.exe from https://code.google.com/p/chromedriver/downloads/list, place it in the bin folder

2013-04-08_09-45-49

Change the driver in the code to Chrome then run the test

driver = new OpenQA.Selenium.Chrome.ChromeDriver();

2013-04-08_09-45-09

Running the test, chrome will open, and Google search page will be displayed, displaying search results then closed

2013-04-08_09-51-36

This was a step by step example on running selenium test from visual studio

Wednesday, April 11, 2012

Running selenium tests from visual studio

I was doing some testing using selenium, the way I was running tests at the beginning is through NUnit,  I thought to give it a try to use the visual studio to run the tests instead.

In visual studio 2010, I created a test project, added a new class file to it, named it selenium test

Added the basic test functions and attributes

the class attribute, and changed the class to be public

    [TestClass()]
public class SeleniumTest


Added Initialization and Cleanup methods



        [TestInitialize()]
public void MyTestInitialize()
{

}

[TestCleanup()]
public void MyTestCleanup()
{

}


Added my test method



        [TestMethod()]
public void TheApplyByQIDWebControlTest()
{

}


Next I took my initial cs file generated from Selenium IDE, opened it, mapped from NUnit functions to VS test functions, so code in [SetUp] went to [TestInitialize()] , code from [TearDown] went to [TestCleanup()] , code from [Test] went to the [TestMethod()]



I also added reference to selenium .NET dlls, built the project with no errors



Next I opened the Test View, my test method appeared in it, I clicked on run, the test started and I was able to run selenium test from visual studio

Friday, February 10, 2012

Creating set of folders for test data with specific IDs

I have been given 150 ID and was told to create folders matching already existing folders for some other IDs. The IDs are to be used as a test data and the folder must exist for each ID to be valid.
I took some time to think how to do this efficiently and in a smart way saving time and effort, and I thought of something to be done
First I went to the ID folder that I already have, did select all, then copy and past several times at the same location, this will create multiples of this folder depending on how times you do select all, copy, past. No of end folders = 2^n, then I adjusted the number so that I have 150 only
Screenshot-2012-02-11_00.16.49
Now I have 150 folder but with incorrect names, Next I should rename to my IDs
Second I opened command prompt, went to that folder that contains the 150 folder, typed dir command and set the output to text file
dir /w >temp.txt
Screenshot-2012-02-11_00.24.57
No I have a text file containing the 150 folder name, the temp names
Third, I opened excel, and in blank sheet, first column I entered “ren “, second row I pasted the 150 temp folder names, third column I pasted the IDs, fourth cell I concatenated all the previous cells. Make sure to replace [ , ] with “
Screenshot-2012-02-11_00.36.29
No I have 150 rename command from the old temp folder names to the new IDs
Last, I selected  the 150 ren command, copied them, then in the command prompt, I did a right click then selected past. The 150 ren command will be executed
Screenshot-2012-02-11_00.42.17
Now, I have my 150 folder for my 150 ID created in a smart and efficient way
Screenshot-2012-02-11_00.42.30


Of course there are other ways to do this, like later, I did a small program to create folders just with one click.