Community in read only mode June 18 & 19
This community will be set in READ ONLY mode for a while on Tuesday June 18 into Wednesday June 19 while we import content and users from our Micro Focus Forums community site. MORE INFORMATION

Keyword-driven testing with Selenium

Micro Focus Contributor
Micro Focus Contributor
7 4 5,774

Simplify your Selenium test creation with keyword-driven testing. Save time and maintenance by building up your test designs so that keywords can be reused across multiple testing scenarios. Allow business stakeholders to create tests independently from implementation and start testing as early as possible in your Software Development Life Cycle (SDLC).

Silk Central provides a web interface to create keyword-driven tests without the need to install any additional tool.

Advantages of Keyword-Driven Testing

The advantages of using the keyword-driven testing methodology are the following:

  • Keyword-driven testing separates test automation from test case design, which allows for better division of labor and collaboration between test engineers implementing keywords and subject matter experts designing test cases.
  • Tests can be developed early, without requiring access to the application under test, and the keywords can be implemented later.
  • Tests can be developed without programming knowledge.
  • Keyword-driven tests require less maintenance in the long run. You need to maintain the keywords, and all keyword-driven tests using these keywords are automatically updated.
  • Test cases are concise.
  • Test cases are easier to read and to understand for a non-technical audience.
  • Test cases are easy to modify.
  • New test cases can reuse existing keywords, which among else makes it easier to achieve a greater test coverage.
  • The internal complexity of the keyword implementation is not visible to a user that needs to create or execute a keyword-driven test.

Create a library

Before you can start with keyword-driven testing, you need a library which will hold your keywords that can be shared across tests. Select Libraries from the Tests menu and create a new library.

Start writing a keyword-driven test

To create the first keyword-driven test:

  1. Click Tests in the menu and create a new test container.
  2. Select the new container and click New Child Test in the toolbar.
  3. Specify a name and select Keyword-Driven Test from the Type list.
  4. Select the previously created library and click Finish

After saving the test, select the Keywords tab and start writing your test. This may look like:


The orange exclamation marks indicate that there is no automation code associated with the keyword.

Implement keywords with Selenium using Java

To implement the draft keywords:

  1. Select Help > Tools and download the Java Keyword-Driven Library Builder.
  2. Add the downloaded to the classpath of your Selenium project.
  3. Create a Java class that will contain your keywords.
  4. Create Java methods called as the keywords in your test. The methods need the same number of parameters as the keyword.
  5. Annotate your methods with the annotation from the downloaded jar.

The Selenium implementation for the keywords of the tests shown in the previous section may look as follows:

public class Keywords {
  private WebDriver driver;

  public void openBrowser(String url) {
    driver = new FirefoxDriver();

  public void login(String email, String password) {

  public void checkLoggedInAs(String fullName) {
    Assert.assertEquals(fullName, driver.findElement(By.xpath(".//*[@class='login']")).getText());

  public void closeBrowser() {

Generate a library and upload to Silk Central

To generate a keyword-driven library:

  • Compile your sources and create a Java archive (jar).
  • Call the DocBuilder class that is contained in the downloaded jar file with the following arguments:
    • Library name to be generated.
    • Java (fixed value).
    • Binaries path where your keyword library jar file resides and if applicable, any other required libraries.
    • Name of the output library package (zip archive) to be generated.

    The following example outlines the command line to execute the DocBuilder:

    java -cp ./ MyLibrary Java ./output ./

    Note: Check the Silk Central online help for the command if you are using a newer version than 16.0.

    To upload your library to Silk Central:

    • Select Libraries in the Tests menu.
    • Select the library you have created previously.
    • Upload the generated zip file on the Properties tab.

    When jumping to your previously created keyword-driven test, you will see that the orange markers are gone and your test is ready for execution.

    Execute keyword-driven tests and Cross-Browser testing

    Please check the previous blog to see how:

    • To schedule your keyword-driven tests for execution.
    • To execute simultaneous cross-browser tests.
    • To get a powerful result analysis including the following:
      • Videos of each test run.
      • Screenshots of the application when a test fails.
      • Log files

    Structuring your keyword library

    Once your keyword library starts to grow you need to bring some structure into your library. Split up your keywords into different classes and apply the annotation @KeywordGroup("Groupname") to each of these.

    The annotation for the class containing keywords related to your main page might look like:

    public class MainPageKeywords

    The keyword-driven test editor will show these groups, which can also be used for filtering:


    Keyword sequences

    A keyword sequence is a keyword that is a combination of other keywords, which are often executed together. Keyword sequences are also stored in the library, which allows you to better structure your keywords, reducing maintenance effort and keeping your tests well-arranged.

    Enhanced naming

    To use characters for your keyword name that are not allowed in Java methods, you can add a String argument to your annotations. This works for keyword names as well as for parameter names. Here is a sample using these arguments:

    @Keyword("My Keyword")
    public void myKeyword(@Argument("User name") String name) {


    Input parameters

    In Silk Central, parameters are freely configurable values that can be used as input for your keywords. Let's assume you want to execute the test of the previous section against different test systems, using different URLs; Therefore we have to specify a parameter name for the openBrowser keyword instead of an explicit URL. Parameters are specified using the following notation:


    For our sample this would look like:


    Now you can execute the same test against different systems by simply passing the URL as parameter.

    Output parameters

    Sometimes it is necessary to get a value from one keyword and use it in a following keyword. By default a parameter of a keyword method is an input parameter. To define an output parameter, use the class OutParameter for the method parameter.

    The code of a keyword returning the number of rows in a grid might look like this:

      public void getNumberOfRowsInGrid(OutParameter nrOfRows) {

    The keyword-driven test editor in Silk Central shows output parameters with a different background colour:


    In the sample above the first row assigns the returned value to a parameter called numberOfRows. The following keywords can then use this parameter as normal input parameter.


    A free 45 day product trial can be downloaded at:

Anonymous3 Absent Member.
Absent Member.

Are you doing test automation with Selenium and facing a rapidly growing amount of tests? Are you looking

Anonymous3 Absent Member.
Absent Member.

Are you doing test automation with Selenium and facing a rapidly growing amount of tests? Are you looking

rekhasunkara Absent Member.
Absent Member.


This is an excellent piece of information on selenium key word driven testing.  I have a question on this hoping you would be able to help me out.

I am currently using SilkCentral 16.5

I have created a selenium project with keywords and uploaded the keyword library from eclipse silk central configuration capability. I am successfully able to run the test as in the web driver has opened the browser and finished all steps.... central is unable to identify the job completion and keep showing Running <Test name>

From the above:

1. Doesnt seem like you are using junit anywhere...if so...can you help me know which version of junit silk central 16 uses

2. How does silk central know job has finished? when the last keyword has completed and entire test has no errors?

3. Does the selenium tests needs to be run as junit test type even though underlying its keyworddriven java test case methods?

any help would be highly appreciable as I am spending days together to understand the silk central test case statuses.

Micro Focus Contributor
Micro Focus Contributor


1. Silk Central is shipped with JUnit 4.11

2. When the execution of the last keyword returns the test is finished. If a keyword threw an error the test will show up as failed.

3. If you are using the keyword-driven feature in Silk Central the tests will have the type "keyword-driven". This is the type where you can specify the steps of the test using the keywords of the uploaded library.

If you want you can also create normal JUnit tests driving Selenium, but then you can't use the keyword-driven editor in Silk Central. In this case the test needs to be configured as JUnit test in Silk Central.

It seems that in your case something hangs and avoids that the test process can exit.

Can you try the Keywords code from the blog, upload the library and create a simple test that just calls the keywords "openBrowser" and "closeBrowser" or just call a keyword that writes to the System.out. Execute the test and see if this is also hanging.

Best Regards,


The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.