A set of formatters to the Selenium IDE that generate friendly C# tests.
These formatters will generate tests that share common code, such as setup, and teardown. In addition, common methods emitted by the default C# / WebDriver format are included as well:
- bool IsElementPresent(By by)
- string CloseAlertAndGetItsText()
These formatters are also able to detect if the tests are running in the Jenkins CI environment, and they will change the application URL being tested to test the designated build. These application URLs will need to be changed to suit your solution and CI configuration.
- Create a class library project to your solution.
- Add the BaseTest.cs file to this project.
- Adjust the namespace of the class to match your project
- Adjust the solution name/web application to test
- Adjust the deployed name/web application to test
- You may rename this BaseTest class name if you choose.
Selenium IDE Setup
- Open Firefox and the Selenium IDE
- In the Selenium IDE, select Options from the Options menu.
- Select the "Formats" tab.
- Click on the "Add" button.
- Name the format: I prefer "C# / WebDriver / Chrome"
- Copy the content of the formatter file: c#-webdriver-ch.js
- Paste the contents of the file in the main text area of the "Selenium IDE Format Source" window.
- Click on the "Save" button. Note: There is currently a bug where the format doesn't appear immediately. Close the Options window and re-open it, and the format will appear in the list.
- Select the format from the list.
- Change the "Namespace" field to match your project's namespace.
- I like to change the "Category" field to match the browser driver used.
- Change the "Base Class" field if you renamed the BaseTest class.
- Repeat steps 4-12 for additional drivers (Firefox, Explorer).
Using the Selenium IDE, create your browser tests like usual, with one minor tweak:
- Insert at
storeExpressioncommand at the very beginning of the test.
- Set the target of the command to the name of the web application (e.g. "/WebApplication1/")
- Set the value of the command to
- Set the second command in the test to
- Set the target of the
These modifications will allow the BaseTest class to set the URL, which is helpful when integrating into the Jenkins CI. When it comes time to export your Selenium test, export the test with the new formats:
- In the Selenium IDE, select "Export Test Case as ..." from the File menu.
- Choose the format. In the example above, the format would be named "C# / WebDriver / Chrome"
- Save the file as a .cs file in your test class library project. I like to give the class a suffix of "-chrome", to distinguish which driver is used for each test class. The filename would then be "TheTest-chrome.cs".
- Go back to your solution, and add the new source file to your test project.
- Compile and run tests!
Please note any issues with these formats in the issues section of this project: