Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. 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

Sunday, July 8, 2012

Mostly used visual studio keyboard shortcuts

below are the shortcuts that I mostly  use in visual studio, descriptions taken from http://msdn.microsoft.com/en-us/library/da5kh0wa.aspx

shortcut

description

CTRL+F Displays the Quick tab of the Find and Replace dialog box.
CTRL+SHIFT+F Displays the In Files tab of the Find and Replace dialog box.
CTRL+H Displays the replace options on the Quick tab of the Find and Replace dialog box.
CTRL+SHIFT+H Displays the replace options on the In Files tab of the Find and Replace dialog box.
CTRL+F3 Finds the next occurrence of the currently selected text, or the word at the cursor.
CTRL+SHIFT+F3 Finds the previous occurrence of the currently selected text, or the word at the cursor.
F3 Finds the next occurrence of the search text.
SHIFT+F3 Finds the previous occurrence of the search text.
CTRL+K, R or SHIFT+F12 Displays the list of references for the selected symbol.
F7 View code, For the selected item, opens the corresponding file and puts the cursor in the correct location.
SHIFT+F7 Switches to Design view for the current document. Available only in Source view.
F12 Go to definition
CTRL+M, CTRL+A Collapses all regions on the page to show just the outermost groups in the hierarchy; typically the using/imports section and the namespace definition.
CTRL+M, CTRL+T Hides the selected HTML tag and displays an ellipsis (. . .) instead. You can view the complete tag as a tooltip by putting the mouse pointer over the ellipsis.
CTRL+M, CTRL+O Collapses existing regions to provide a high-level view of the types and members in the source file.
CTRL+K, CTRL+D or CTRL+E, D Formats the current document according to the indentation and code formatting settings specified on the Formatting pane in the Options dialog box, for the current language.
CTRL+L Cuts all selected lines, or the current line if nothing has been selected, to the Clipboard.
CTRL+SHIFT+L Deletes all selected lines, or the current line if no selection has been made.

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