<dependency>
<groupId>com.github.wasiqb.coteafs</groupId>
<artifactId>datasource</artifactId>
<version>1.0.0</version>
</dependency>
Pojo class for our data file login-data.yml
.
import java.util.List;
import com.github.wasiqb.coteafs.datasource.annotation.DataFile;
import lombok.Data;
@Data
@DataFile
public class LoginData {
private List<Login> loginData;
}
@Data
public class Login {
private String password;
private String userName;
}
Data for our Yml data file login-data.yml
.
login_data:
- user_name: WasiqB
password: Admin
- user_name: FaisalK
password: Abcd
Following is an example to convert data file into a TestNG data provider.
import static com.google.common.truth.Truth.assertWithMessage;
import com.github.wasiqb.coteafs.datasource.data.LoginData;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class DataSourceYmlTest {
@DataProvider
public Iterator<Object[]> getLoginDataYml () {
final LoginData loginData = DataSource.parse (LoginData.class);
final List<Object[]> data = new ArrayList<> ();
loginData.getLoginData ()
.forEach (d -> data.add (new Object[] { d }));
return data.iterator ();
}
@Test (dataProvider = "getLoginDataYml")
public void testYmlDataSource (final Login login) {
assertWithMessage ("User Name").that (login.getUserName ())
.isNotEmpty ();
assertWithMessage ("Password").that (login.getPassword ())
.isNotEmpty ();
}
}
Thanks to these wonderful people (emoji key):
Mohammad Faisal Khatri |
Wasiq Bhamla ๐ป |
This project follows the all-contributors specification. Contributions of any kind welcome!