Welcome to OGeek Q&A 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 |
| test@gmail.io| 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 Reply

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" : "test@gmail.io" , "password":"123abc123" , "isvalid":false },
    { "username" : "Admin" , "password":"test" , "isvalid":false },
    { "username" : "admin" , "password":"Admin2193" , "isvalid":true }
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...