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...