Monday 30 April 2018

Gherkin: Internationalisation support

Cucumber supports 40+ langauges. You can write the .feature file in any of the language. But you need to specify the language that you are using by putting ‘#langauge’ as the first line of the .feature file.

How to get all the langauges supported by Gherkin?
Copy all the cucumber relevant jars into a directory called ‘jars’.

For example, I copied below jars to 'jars' directory.
cucumber-core-2.3.1.jar
gherkin-5.0.0.jar

Go to the parent directory of 'jars' directory and run below command.
java -cp "cucumber_jars/*;." cucumber.api.cli.Main --i18n help

C:\Users\krishna\Documents\Study\cucumber>java -cp "cucumber_jars/*;." cucumber.api.cli.Main --i18n help
af
am
ar
ast
az
bg
bm
bs
ca
cs
cy-GB
da
de
el
em
en
en-Scouse
en-au
en-lol
en-old
en-pirate
eo
es
et
fa
fi
fr
ga
gj
gl
he
hi
hr
ht
hu
id
is
it
ja
jv
ka
kn
ko
lt
lu
lv
mk-Cyrl
mk-Latn
mn
nl
no
pa
pl
pt
ro
ru
sk
sl
sr-Cyrl
sr-Latn
sv
ta
th
tl
tlh
tr
tt
uk
ur
uz
vi
zh-CN
zh-TW


How to get the language codes associated with specific language?
Below command return all the keywords associated with language code id.
java -cp "cucumber_jars/*;." cucumber.api.cli.Main --i18n id

C:\Users\krishna\Documents\Study\cucumber>java -cp "cucumber_jars/*;." cucumber.api.cli.Main --i18n id
      | feature          | "Fitur"           |
      | background       | "Dasar"           |
      | scenario         | "Skenario"        |
      | scenario outline | "Skenario konsep" |
      | examples         | "Contoh"          |
      | given            | "* ", "Dengan "   |
      | when             | "* ", "Ketika "   |
      | then             | "* ", "Maka "     |
      | and              | "* ", "Dan "      |
      | but              | "* ", "Tapi "     |
      | given (code)     | "Dengan"          |
      | when (code)      | "Ketika"          |
      | then (code)      | "Maka"            |
      | and (code)       | "Dan"             |
      | but (code)       | "Tapi"            |


For example, below feature file is written in Indonesian language. You can observe I added #language statement at first line.

Login.feature

#language: id
# This feature checks the login flow of the user.

Fitur: Login

    Login should be quick and friendly. When user logged in with correct credentials, then he would be greeted with welcome message.
    If user session is expired, he should be reverted back to login page.

    # Check the happy Scenario  
    Skenario: Successful Login 
    User should be logged in successfully by providing correct username and password.
            
        Dengan I am registered user to the application 
        Ketika I log in with user name "krishna" and password "password123" 
        Maka I should be logged in successfully 
        Dan I should see a personalized greeting message 
    
    # Checks session expiration scenarion
    Skenario: Session Expired 
    User should be redirected to login page on session expiration
    
        Dengan I am the logged in user to the application 
        Tapi My session is expired 
        Ketika I try to interact with the application 
        Maka I should be notified about session expiration 
        Dan I should be redirected to the login page

When I generate the code using cucumber, it generates below skelton.

@Dengan("^I am registered user to the application$")
public void iAmRegisteredUserToTheApplication() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Ketika("^I log in with user name \"([^\"]*)\" and password \"([^\"]*)\"$")
public void iLogInWithUserNameAndPassword(String arg1, String arg2) throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Maka("^I should be logged in successfully$")
public void iShouldBeLoggedInSuccessfully() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Maka("^I should see a personalized greeting message$")
public void iShouldSeeAPersonalizedGreetingMessage() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Dengan("^I am the logged in user to the application$")
public void iAmTheLoggedInUserToTheApplication() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Dengan("^My session is expired$")
public void mySessionIsExpired() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Ketika("^I try to interact with the application$")
public void iTryToInteractWithTheApplication() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Maka("^I should be notified about session expiration$")
public void iShouldBeNotifiedAboutSessionExpiration() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Maka("^I should be redirected to the login page$")
public void iShouldBeRedirectedToTheLoginPage() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}


Previous                                                 Next                                                 Home

No comments:

Post a Comment