Posts

Showing posts from October, 2010

Selenium With .Net

Recently I had a chance to work with Selenium framwork. It is pretty easy to intrgrate automated testing into .net with Selenium. Also for project like web site scrapping and automated posting, can be easily developped with few lines of code. Following code lines will automate a web site login with use of selenium framework. ISelenium selenium = new DefaultSelenium(seleniumServer, port, browser, website); selenium.Start(); selenium.Open(ConfigLoader.Configurations.LoginPageUrl); selenium.WaitForPageToLoad((ConfigLoader.Configurations.WaitingTime * 1000).ToString()); selenium.Type("ctl00_PageContent_UserName", ConfigLoader.Configurations.UserName); selenium.Type("ctl00_PageContent_Password", ConfigLoader.Configurations.Password); selenium.Click("ctl00_PageContent_OKButton__Button"); selenium.WaitForPageToLoad((ConfigLoader.Configurations.WaitingTime * 1000).ToString());

Error in parsing Convert.ToDouble or double.Parse for decimal values in C#

I found that one of my client's application showing "0,00" for pricing column of his application, and found that it works find on my pc. Once I traced the error, I found that it fails when parsing price like "1500.00" with Convert.ToDouble or double.Parse. The reason for that is, the particular client using Finnish currency format, which is like "1500,00". As you see the difference is they use "," instead of "." for decimal separation. If you want to convert decimal (money) values in string format, which will universally work in every where, you have to use following code snippet.             string pricetext = "5535.25";             string[] parts = pricetext.Split('.');             double price = Convert.ToDouble(parts[0]);             if (parts.Length == 2)             {                 dec = Convert.ToInt32(parts[1]);                 price += (dec * 0.01);             }