O'Reilly logo

Selenium WebDriver Recipes in C#, Second Edition by Zhimin Zhan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 15

image

Test Data

Gathering test data is an important but often neglected activity. With the power of C# programming, testers now have a new ability to prepare test data.

Get date dynamically

// assume today is 2014-12-29String todaysDate = DateTime.Now.ToString("MM/dd/yyyy");Console.WriteLine("todaysDate = " + todaysDate);driver.FindElement(By.Name("username")).SendKeys(todaysDate); //=>12/29/2014

A more flexible way is to write some helper functions to return common dates.

Today("dd/MM/yyyy"); // => 29/12/2014Tomorrow("AUS");     // => 30/12/2014Yesterday("ISO");    // => 2014-12-28public static String GetDate(String format, int dateDiff) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required