There is such a thing - Test Data-Pool. Seems to be usefull and there are usage examples but still it is not absolutely clear how-to start.
Given there are tests based on Java+testNG+maven + something else. Let's start:
1. Add maven dependency
Specify actual version of course.
2. Greate/find entities package. Add a new entity class
package ru.test.automation.entities;
import com.griddynamics.qa.datapool.DataTypeFactory;
import com.griddynamics.qa.datapool.datatype.IDataType;
/**
* Represents a BitBucketUser entity.
*/
public interface BitBucketUser extends IDataType {
static BitBucketUser newUser(){
return DataTypeFactory.create(BitBucketUser.class);
}
Integer getId();
String getLogin();
String getPassword();
}
Field set could be different.
3. Greate/find /resources/data directory and add the data-file
!DataTypeKey 'interface ru.test.automation.entities.BitBucketUser':
- !IDataType {id: 1, login: Uzvr_Odin, password: Klu4slovo}
- !IDataType {id: 2, login: uzvr-Dva, password: derParrollen}
- !IDataType {id: 3, login: uzvr-Tri, password: AEtoKto?}
Let's name the file as ls.yml
4. Highly likely there is a BaseTest so add the following to it
import ru.test.automation.entities.BitBucketUser;
import com.griddynamics.qa.datapool.DataPool;
import static com.griddynamics.qa.datapool.FilterCriterion.by;
import static com.griddynamics.qa.datapool.matchers.StandardMatchers.CONTAINS;
...
@BeforeSuite
protected void loadData() {
ClassLoader classLoader = getClass().getClassLoader();
DataPool.load(Paths.get(classLoader.getResource("data/ls.yml").getPath()));
// TODO: Switch to the approach below when Data-pool 1.0.2 is released.// DataPool.load("data/ls.yml");
}
//TODO: Think about moving into a separate data-access class.
protected BitBucketUser getUserByLogin(String partOfLoginName) {
return DataPool.find(BitBucketUser.class, by("login", CONTAINS, partOfLoginName)).get(0);
}
5. And finally, within a test
BitBucketUser usr = getUserByLogin("Uzvr_Odin");
loginPage().login(usr.getLogin(), usr.getPassword());