Saturday, December 8, 2012

How to execute Compound class names using WebDriver

If you have a Compound class and you want to do something like this:
IWebElement elem = Browser.Driver.FindElement(By.ClassName("name1 name2 name 3"));

you will get an error like:
"Compound class names are not supported. Consider searching for one class name and filtering the results."

The solution:
Use CssSelector, and put "." in front of each name, like this:
IWebElement elem = Browser.Driver.FindElement(By.CssSelector(".name1.name2.name 3"));

Remove utorrent toolbar from Chrome

If you have this annoying problem here is how to fix it:

1. Go to C:\Users\[Username]\AppData\Local\ and remove CRE and Conduit directories.
2. Start -> regedit -> search for '\AppData\Local\CRE' and remove any related Extensions.


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());
}


Tuesday, August 21, 2012

Coded UI - Close process by process name


This is an example to close Firefox, but can be used for any other process:

//close Firefox
            Process[] processes = Process.GetProcessesByName("firefox");
            foreach (Process process in processes)
            {
                process.Kill();
                process.WaitForExit();
            }  

Coded UI - Add messages in Results

If you need messages in Results:

Assert.Fail("Login page not available"); - test will fail and the message will be displayed in Results
this.TestContext.WriteLine("Login page available"); - test will pass and the message will be displayed in Results

Coded UI - Select text and replace


This is useful sometimes:

Mouse.Click(this.TestRunner.Login.UIMozillaWindow.UIItemDocument.UIGeneralPasswortEdit);
Keyboard.SendKeys(this.TestRunner.Login.UIMozillaWindow.UIItemDocument.UIGeneralPasswortEdit, "A", ModifierKeys.Control);
Keyboard.SendKeys("1234567");   

Monday, August 20, 2012

"Conversation in the Cathedral" by Mario Vargas Llosa


    It's been a while since I wrote about books. Maybe too long, I've read 2 books, but found no time to write about them.

    Chronologically, "Conversation in the Cathedral" by Mario Vargas Llosa is the first.

    This was one of my personal, hardest to read, books. Many times I found myself lost in the action and had to return few paragraphs to confirm what was happening.
The story is like a puzzle, only that Llosa connected the pieces in a long straight line. Try to see the final picture J
Even if it is a book of not so many pages, it took the longest to read. It was a busy period for me too, but still.

    How about if I liked it? Well… that’s also hard to say.
There are 2 leading characters Zavalita and Ambrosio.
Zavalita(Santiago Zavala) is the son of don Fermin (a wealthy man during the Odria dictatorship) and Ambrosio is one of don Fermin’s drivers.
The story starts at the end, when the 2 meet at “The Cathedral” pub. They start talking about the past and how their lives turned out.
About here the maze starts.

    Born in a wealthy family, Santiago refuses the benefits all his life. He denies his family and goes into the world on his own, living in mediocrity.
Somehow, I got the feeling he was mostly happy with his decisions.

    Ambrosio, on the other hand, as don Fermin’s driver, is thrown deeply in the high society intrigues.
He knows about all the ugly stuff. The political manipulation and deceits, about the whores and illegal luxury, about the killers and the dark secrets of his employer.
One lives in his ignorance and the other in fear.

    It is an interesting book, if you consider the way it’s written. It’s not pleasant to read if you consider the action and the characters.
In the end you feel disappointment; of the world Llosa presents or of the world we live in, I don’t know.

    This is the point where I’ll take a break from Mario Vargas Llosa, cool down and read some fantasy.
Something like “Song of ice and fire” series by George R. R. Martin. I have already read the first book “A Game of Thrones”. When I get some time I will write about it.

Keep reading! :)

Thursday, July 12, 2012

Open cmd.exe in specific directory

If you need to open cmd.exe in specific directory and run a command, here is what you need to do:

var processStartInfo = new ProcessStartInfo();
processStartInfo.WorkingDirectory = @"c:\";
processStartInfo.FileName = "cmd.exe";

// set additional properties     
Process proc = Process.Start(processStartInfo);

Wednesday, July 11, 2012

Representing quotes inside string in C#


For:
Ana said "apples"!

string myString = "Ana said \"apples\"!";
string myString = @"Ana said ""apples""!";

Rules:
 - add \ before quotes you want to keep;
 - double the quotes and use @ at the begining.

Working with XML

1. Format xml file so it looks nice:


 public static String FormatXML(String XML)
        {
            String Result = "";


            MemoryStream mStream = new MemoryStream();
            XmlTextWriter writer = new System.Xml.XmlTextWriter(mStream, Encoding.Unicode);
            XmlDocument document = new XmlDocument();


            try
            {
                // Load the XmlDocument with the XML.
                document.LoadXml(XML);


                writer.Formatting = Formatting.Indented;


                // Write the XML into a formatting XmlTextWriter
                document.WriteContentTo(writer);
                writer.Flush();
                mStream.Flush();


                // Have to rewind the MemoryStream in order to read
                // its contents.
                mStream.Position = 0;


                // Read MemoryStream contents into a StreamReader.
                StreamReader sReader = new StreamReader(mStream);


                // Extract the text from the StreamReader.
                String FormattedXML = sReader.ReadToEnd();


                Result = FormattedXML;
            }
            catch (XmlException)
            {
            }


            mStream.Close();
            writer.Close();


            return Result;
        }


2. To be continued...

Wednesday, June 27, 2012

Web test plugin to encode to base64


This is a Web Performance test plugin that get's the values from 2 context parameters and encrypts them in base64, before running the call:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.WebTesting;


namespace Base64
{
    public class Encrypt64 : WebTestPlugin
    {
        [System.ComponentModel.DisplayName("Context Parameter Name")]
        [System.ComponentModel.Description("Name of the webtest context parameter")]
        public string ContextParameterName
        {
            get;
            set;
        }


        // encode to Base64 function
        static public string EncodeTo64(string toEncode)
        {
            byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
            string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
            return returnValue;
        }


        // decode from Base64 function
        static public string DecodeFrom64(string encodedData)
        {
            byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
            string returnValue = System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
            return returnValue;
        }


        // this will be executed before the call
        public override void PreWebTest(object sender, PreWebTestEventArgs e)
        {            
            string decode64;
            decode64 = EncodeTo64(e.WebTest.Context["email"] + ":" + e.WebTest.Context["pass"]);
            e.WebTest.Context["GetBase64"] = decode64;
        }


        // this will be executed after the call
        public override void PostWebTest(object sender, PostWebTestEventArgs e)
        {
        }
    }
}

Tuesday, June 26, 2012

Custom Web Performance Rules


Create a Custom Extraction Rule for a Web Performance Test
http://msdn.microsoft.com/en-us/library/ms243179.aspx

Create a Custom Validation Rule for a Web Performance Test
http://msdn.microsoft.com/en-us/library/ms182556

Create a Web Performance Test Plug-In
http://msdn.microsoft.com/en-us/library/ms243191.aspx

Custom Extraction Rule - Extract Cookie Value
http://social.msdn.microsoft.com/Forums/en-US/vstswebtest/thread/cf2bf144-4e87-414f-8aa3-7731f9bc7b73/

Encode/Decode to Base64


//Encode

static public string EncodeTo64(string toEncode)
    {
      byte[] toEncodeAsBytes
            = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
      string returnValue
            = System.Convert.ToBase64String(toEncodeAsBytes);
      return returnValue;
    }


//Decode

    static public string DecodeFrom64(string encodedData)
    {
      byte[] encodedDataAsBytes
          = System.Convert.FromBase64String(encodedData);
      string returnValue =
         System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
      return returnValue;
    }


//Usage

      string myData = “Here is a string to encode.”;

      string myDataEncoded = EncodeTo64(myData);
      Console.WriteLine(myDataEncoded);

      string myDataUnencoded = DecodeFrom64(myDataEncoded);
      Console.WriteLine(myDataUnencoded);

      Console.ReadLine();

Link where I got this from:
http://arcanecode.com/2007/03/21/encoding-strings-to-base64-in-c/

401 - Unauthorized error in Web Performance test

Scenario:
1. In a Visual Studio Web Performance test, make call to a web service that requires credentials.
=> you will get 401 - Unauthorized error (if you did not specify credentials)

Solution:
1. Add a Header (for Basic authentication) to the web test request: Right-click on the call -> Add Header.

2. Add the following info:
Name: "Authorization"
Value: “Basic ” + encodeBase64 (“username:password”)

Use http://www.base64encode.org/ to encode username and password in the following format: "username:password".

It should look like this:

Tuesday, June 19, 2012

RESTClient - usefull tool when working with REST services

You can download the tool from here:
https://addons.mozilla.org/en-US/firefox/addon/restclient/

After installting the Firefox addon you can use it to create all kinds of calls to the REST service.


Monday, June 18, 2012

Nice things you can do with Excel

Excel can be a very useful tool with few tricks.
Here is a collection of some of them:

1. ALT + Enter - to go on second line inside a cell.

2. View -> Freeze Panes -> Freeze top Row.
















3. =IF(logical_test,[value_if_true],[value_if_false]) - to display a result if the logical_test is true or false.

4. =SUMIF(range,criteria,[sum_range]) - to add elements in a range that match given criteria.

5. =COUNTIF(range,criteria) - to count elements in a range that match given criteria.


6. =COUNT(value1,[value2],...) - to count the number of cells in a range that contain numbers.


7. =COUNTBLANK(range) - to count number of blank cells in a range.

8. =COUNTA(value1,[value2],...) - to count the number of cells in a range that are not empty.

9. =OR(logical1,[logical2],...) - logic OR. Same for AND and NOT.

10. =SUM(number1,[number2],..) - to add numbers

11. =CONCATENATE(text1,[text2],...) - to concatenate strings

12. =VALUE(text) - to convert text to numbers

13. =TRIM(text) - to remove all spaces from a string

14. =ROUND(number,num_digits) - to round a number with specified number of digits.

15. =INT(number) - to round a number to the closest integer.

16. =RANDBETWEEN(top,bottom) - generates random number in given range.

17. =ISBLANK(value) - returns True if blank and False otherwise.

18. =CONVERT(number,from_unit,to_unit) - used to convert from a unit to another.

19. Home -> Conditional Formating.























Have fun :)

Monday, May 14, 2012

Run, Alina, run!


    There was a running competition in Timisoara, and I went with my colleagues :) from Haufe-Lexware.
It was cold and windy and I have never run this much in my life, but somehow it was worth it.
I felt like quiting many times, but managed to run 5km in 27:16 minutes, winning a 10th place in the women category: http://www.crosulfirmelor.ro/index.php/ro/rezultate-2012.html

    It was a really interesting experience. I had "Run, Alina, run!" written on the back of my tshirt, and people that I did not know where cheering. That was really nice and gave me a warm feeling of hope that I could do it.

    Here is a foto of me just before the finish line. I'm the one in blue :)
(oh, yeah I did not see that girl coming :P )



Monday, April 30, 2012

Timisoara - Solden


    For all you ski fans out there, if there is one close to perfect place to go, this is for sure Solden in Austria.


    I am going to tell you a little bit about the expenses you might have when tarveling from Timisoara, Romania (my location) to Solden, Austria:
- 26 euro vignette for Hungary and Austria;
- distance Timisoara - Solden ~ 1150 km (made by car in 14 hours, with a 2 hours brake from driving)
- gas prices: an average of 1.6 euro per liter (diesel was arround that price also).
- ski pass: 231 euro for 6 days for one person.

It was a wonderful experience, great slopes and perfect snow. The people were very nice, and the weather was fine and sunny at the begining of March.

The internet however is not so great, it's slow and expensive: 21 euro for 7 days, or 5, 6 euro for 1 hour in restaurants/bars/caffes. Rip-off! if you ask me... and it's really slow, it's like someone is counting the bytes :)
There was free wireless though at the base of the slopes, at the cable cars, and in a mall in Salzburg. Considering it's a vacation, I gues we can live without good internet speed for a few days, right?


Another nice place to go was the Aqua Dome (http://www.aqua-dome.at/xxl/_lang/en/_area/therme/index.html). It's about 18 euro for 3 hours (http://www.aqua-dome.at/xxl/_lang/en/_area/therme/_subArea/532066/index.html), but there's not much you can do there so 3 hours after ski, is more than enough. The thermal spa is relaxing and a good way to recharge your batteries.

You can also visit Budapest, Vienna, Salzburg, Munich along the way, stop at Pandorff if you want and overall enjoy the local hospitality.

That's about it. Solden is one of the nicest places you can visit, especially if you go there for skiing. I fully recomend it :)



Wednesday, April 11, 2012

Remove service from Services.msc

If one of the programs you have uninstalled leaves a service in Services.msc and you want to get rid of it, here is what you can do:
- Go to HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services
- Delete the services that you don't need.
- Restart OS.

Friday, February 17, 2012

"Tabara de Testare" Timisoara

A new event is happening in Timisoara: "Tabara de Testare".
I attended yesterday, with this presentation on Tester Mindset:

http://prezi.com/eoavxqev5stf/tabara-de-testare-2-tester-mindset/

Hope you like it :)
Switch to full screen for the full experience.

Tuesday, January 10, 2012

Exchange Server 2010 EMC Initialization failed because the user was not found it was running 'Get-logonuser'


I have found the following resolution:

"This usually happens in Hyper-V or another Virtualization software, when the same Image that was created is used without Sysprep, EMC will not start if the Machine SID conflicts with Virtual Machine or Host.
To sysprep try to go to c:\windows\system32\sysprep, and make sure you check GENRALIZE."

http://social.technet.microsoft.com/Forums/en-US/exchange2010/thread/375cf88d-4879-4dc9-a522-bcbf6bedc1b0/

VERY IMPORTANT! Run sysprep on clean OS, before installing Exchange.

My scenario:
Install Exchange 2010 SP1 Hub Transport Role and Client Access Role on one machine and Exchange 2010 SP1 Mailbox Role on a different machine. I was using the same 2008 R2 base image. After installing Mailbox Role on the second machine, the Exchange Management console would fail to initialize. So I started from the begining:
- installed Hub Transport and CAS roles one the first machine;
- run sysprep on the clean OS for the second machine;
- installed Mailbox role on the second machine;

=> and no error :)