Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

How to do parameterization using Json in selenium cucumber framework

I am using selenium-cucumber framework in our project. So i have feature file in one package, stepdefinition class in one package and runner class in another package. I have some steps in Feature file as given below.

Feature: To test login of FreeCRM

Scenario Outline: login test
Given user in login page
When title of page is freeCRM
Then user enter <username>
Then user enter <password>
Then user click on login button
And user is in home page

Examples:
| username | password |
| [email protected]| test123@ |

So in this structure how can i do parameterization through json instead of giving data through example keyword in feature file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can add qaf-cucumber dependency and it will enable you to use examples from external data providers like xml,json,csv,db,excel. Once you add dependency your scenario can use example form external file and may look like below:

@dataFile:resources/logindata.json
Feature: To test login of FreeCRM

Scenario Outline: login test
Given user in login page
When title of page is freeCRM
Then user enter <username>
Then user enter <password>
Then user click on login button
And user is in home page

Json data file:

[
    { "username" : "[email protected]" , "password":"123abc123" , "isvalid":false },
    { "username" : "Admin" , "password":"test" , "isvalid":false },
    { "username" : "admin" , "password":"Admin2193" , "isvalid":true }
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...