As you probably know I am developing a series posts called- Pragmatic Automation with WebDriver. They consist of tons of practical information how to start writing automation tests with WebDriver. Also, contain a lot of more advanced topics such as automation strategies, benchmarks and researches. In the next couple of publications, I am going to share with you some Advanced WebDriver usages in tests. Without further ado, here are the today's advanced WebDriver Automation tips and trips.

1. Start FirefoxDriver with Plugins

Just use the AddExtension of the FirefoxProfile class to load the desired extension.

2. Set HTTP Proxy ChromeDriver The configuration of a proxy for ChromeDriver is a little bit different from the one for FirefoxDriver. You need to use the special Proxy class in combination with ChromeOptions.

3. Set HTTP Proxy with Authentication ChromeDriver The only difference from the previous example is the configuration of the --proxy-server argument.

While ago when we were working on the first version of the BELLATRIX test automation framework, I did this research and afterward we used many of the tricks in lots of the features of our solution.

4. Start ChromeDriver with an Unpacked Extension Chrome extensions can be either packed or unpacked. Packed extensions are a single file with a .crx extension. Unpacked Extensions are a directory containing the extension, including a manifest.json file. To load an unpacked extension you need to set the load-extension argument.

5. Start ChromeDriver with an Packed Extension Instead of setting the load-extension argument, you need to use the AddExtension method of the ChromeOptions class to set the path to your packed extension.

6. Assert a Button Enabled or Disabled You can check if an element is disabled through the Enabled property of the IWebElement interface.

7. Set and Assert the Value of a Hidden Field You can get the value of a hidden field through the GetAttribute method, part of the IWebElement interface. Get the value attribute of the element. You can set the same attribute with a little bit of a JavaScript code.

8. Wait AJAX Call to Complete Using JQuery jQuery.active is a variable JQuery uses internally to track the number of simultaneous AJAX requests. Wait until the value of jQuery.active is zero. Then continue with the next operation.

9. Verify File Downloaded ChromeDriver To change the default download directory of the current Chrome instance set the download.default_directory argument. When we initiate the file download, we use the WebDriverWait to wait until the file exists on the file system. Finally, we assert the file size. The whole code is surrounded with a try-finally block. In the finally we delete the downloaded file so that our test to be consistent every time.