Wednesday, November 28, 2012

For Chrome Devtools

Here are some useful tips for Chrome Devtools.
I got this from one of my coleagues. Thanks Calin :)

http://anti-code.com/devtools-cheatsheet/

Have fun!

Tuesday, November 20, 2012

Selenium Server Setup

Steps to Setup Selenium Server:

1. Download and Install Java if not available.
http://www.java.com/en/download/index.jsp

2. Download Selenium Server.
http://seleniumhq.org/download/


3. Open Command Prompt in Selenium Server location and run the following command:
java -jar "selenium-server-standalone-2.25.0.jar"



4. In VisualStudio:

IWebDriver driver = 
new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),
                    DesiredCapabilities.Firefox());              

Get XPath using Firefox Firebug

If you need XPath here are 3 simple steps to get it.

1. Open desired page in Firefox (that has Firebug AddOn).

2. Right-click on page element and select Inspect Element with Firebug:


3. Right-click on inspected element and select Copy XPath:


Selenium Webdriver Basics

Some basic Selenium WebDriver stuff:

1. Click a RadioButton:
var radioButton = driver.FindElements(By.Name("colorname"))[0];
radioButton.Click();

2. Get a RadioButton value:

var radioButtons = driver.FindElements(By.Name("colorname"));
foreach (var radioButton in radioButtons)
{
  if (radioButton.Selected)
    Console.WriteLine(radioButton.GetAttribute("value"));
}

3. Check Checkbox:
var checkBox = driver.FindElement(By.Id("checkboxId"));
checkBox.Click();

4. Select from dropdown list:
var select = driver.FindElement(By.Id("elementId"));
var option = select.FindElemets(By.TagName("optionTagName"))[0];
option.Click();

5. Get text row from table:
var table = driver.FindElement(By.TagName("table"));
var row = table.FindElements(By.TagName("td"))[0];
Console.WriteLine(row.Text);

6. Get element using XPath:
var element = driver.FindElement(By.XPath("//*[@id="gbqfq"]"));


7. Implicit waiting:
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));


8. Explicit waiting:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var element = wait.Until(d=>
              {
                   return driver.FindElements(By.ClassName("class"))[0];
               });
element.Click();

Monday, October 29, 2012

Setup Selenium WebDriver

I need to setup Selenium WebDriver with .Net so here are the steps:

1. Download the latest selenium-dotnet zip file from:
https://code.google.com/p/selenium/downloads/list

2. Unblock the zip file before unzipping it: Right click on the zip file, click “Properties”, click “Unblock” and click “OK”.

3. Unzip the contents of the zip file, and add a reference to each of the unzipped dlls to your project in Visual Studio.

4. Get Official NuGet Packages:
http://www.nuget.org/packages/Selenium.WebDriver
http://docs.nuget.org/docs/start-here/using-the-package-manager-console

5. Download Chrome driver from here:
http://code.google.com/p/chromedriver/downloads/list
http://code.google.com/p/selenium/wiki/ChromeDriver

6. In Visual Studio go to Test -> New Test -> name it FirtsSeleniumTest.cs

7. Write the following code:

var driver = new ChromeDriver(@"C:\Selenium\chromedriver_win_23.0.1240.0");
driver.Navigate().GoToUrl("http://www.google.com/");
var query = driver.FindElement(By.Name("q"));
query.SendKeys("My first Selenium test");
query.Submit();

8. Run the code. This will open google and type "My fisrt Selenium test".

Friday, August 24, 2012

Pixel and color friendly Firefox Addons

This 2 tools are of huge help when you need to validate colors and sizes in a pixel perfect application :

1. https://addons.mozilla.org/en-US/firefox/addon/measureit/
- you can see code behind
- you can see a cool 3D layered image of your application

2. https://addons.mozilla.org/en-us/firefox/addon/pixelzoomer/
- perfect for measuring sizes
- accurate color picker

Thursday, August 23, 2012

Coded UI - Find link in browser page

Imagine the following scenario:

You need to get all links in a page that share a Property value.


 this.TestRunner.UIMap.UIMozillaWindow.UIItemList.UIHyperlink.WaitForControlExist();
 UITestControl window = this.TestRunner.UIMap.MozillaWindow;            
 window.SearchProperties.Add(BrowserWindow.PropertyNames.ClassName, "MozillaWindowClass");

WinEdit section = new WinEdit(window);
section.SearchProperties.Add(WinEdit.PropertyNames.ControlType, "Edit", PropertyExpressionOperator.Contains);


UITestControlCollection links = section.FindMatchingControls();
foreach (UITestControl x in links)
{                
 // anything you need to do
 MessageBox.Show(x.Name.ToString());
}