Domain Specific Language

Domain Specific Languages are methods that are specifically written to make the API in a very readable format. This would enable a good rapport between the developers and business people.

Selenium provides a test domain-specific language (Selenese). Selenese is a set of commands that is used for running the tests.

We can also write our own DSL, specific to our requirement and customise according to the framework.

Wrapping the Selenium API/WebDriver API’s.

Selenium 1.0:

public void selectFrame(Selenium selenium, String elementName){

A similar example in the WebDriver can be written, a few examples below:

Selenium 2.0

WebDriver by itself dont have any DSL , but we can always build on our own.

public void findElementAndClick(webDriver driver, String elementLocator){

Now you can call the method findElementAndClick to do the click operation.

public void findElementAndType(webDriver driver, String elementLocator,String testData){

Now you can call only the findElementAndType method to perform the operation, this will be more readable and will avoid code duplication.

public void findElementAndExecuteJavaScript(webDriver driver, JavascriptExecutor js, Id id){
JavascriptExecutor js =(JavascriptExecutor)driver;
js.executeScript("return document.getElementById('id');");

Now you can call findElementAndExecuteJavaScript method to perform the JavaScript operation in your tests.

This is just an example and we can always modify according to the requirement and framework.

Hope this helps. Feel free to share and do follow for more posts.

One thought on “Domain Specific Language

Leave a Reply

Your email address will not be published. Required fields are marked *