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 20

image

Leverage Programming

The reason that Selenium WebDriver quickly overtakes other commercial testing tools (typically promoting record-and-playback), in my opinion, is embracing programming, which offers the flexibility needed for maintainable automated test scripts.

In this chapter, I show some examples that use some programming practices to help our testing needs.

Throw exceptions to fail test

Although Visual Studio Unit Testing Framework or NUnit framework provides most of the assertions needed, throwing exceptions can be useful too, as shown below.

string osPlatform = System.Environment.OSVersion.Platform.ToString();System.Console.WriteLine(osPlatform); ...

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