Test Dev Guide
Client API
Add library bali-api.jar to be able to use Bali Client API for writing tests.
In the thread, which is executing current runnable item,
Bali puts TestExecContext in TestExecContextThreadLocal variable.

TestExecContext testExecContext = TestExecContextThreadLocal.getTestExecContext();
Current object contains all information of the test scenario execution: errors, captured states, metrics data e.t.c,
which will be used for reports view generation on front-end, also offers methods for adding these items during test run.
Get objects from the pool
TestExecContext method getResource(RequiredTestResource reqTestResource, [order])
returns instace of TestExecResource.

RequiredTestResource(Class resourceClass, String matchProperties)
resourceClass - class, instance of which You wish to get from resource pool. System will search pool having instances of such class
and then match the one with next param.
String matchProperties - match properties of the instance. TestExecResource offers to reload method match(String a) returning true/false

//get browser matching Firefox number 1. if order param is omitted, then first object is taken.
Browser browser1 = (Browser) TestExecContextThreadLocal.getTestExecContext().getResource(new RequiredTestResource(Browser.class, "Firefox"));

//get browser matching Firefox number 2
Browser browser2 = (Browser) TestExecContextThreadLocal.getTestExecContext().getResource(new RequiredTestResource(Browser.class, "Firefox"), 2);

In order tests to run smooth need to assume correct resource pool setup (resources quantity, types) in config file projects.xml.
Creating resource pool and resource class

1) Implement test execution resource class (extends TestExecResource)

public boolean init(TestExecContext testExecContext) throws Exception
public boolean isFree()
public boolean isFree(TestExecContext testExecContext)
public boolean match(String match)
public boolean matchRequirements(String properties)
public boolean isFree(TestExecContext testExecContext, String properties)
public boolean isFree(String properties)

2) Implement resource pool factory (implements ResourcePoolFactory)

method getResourceClass() should just return defined class, meaning current factory is producing only this kind of instances.)
method load receives string with lexical description of resources to be instantiated and added to resource pool for further use in test.
method getLoadCmdHelp() should return String with description of how to write argument for load(String cmd) method.

public interface ResourcePoolFactory {
public ArrayList load(String cmd);
public String getLoadCmdHelp();
public Class getResourceClass();
}

3) Add resource pool to project

ResoucePool tag is defining project's resource pool object.

Put classname to factoryclass and list of commands You wish to instantiate the pool by the factory (method load).
projects.xml

< project>

< adapterclass >...< /adapterclass >
< config > ... < /config >
< ResourcePool >

< !-- set factory class, it should be implementing ITestExecResourceFactory interface -- >
< factoryclass >org.kkonoplev.bali.selenium.browser.BrowserFactory< /factoryclass >
< loadcmd >3,,false,firefox< /loadcmd >
< loadcmd >2,,false,chrome< /loadcmd >

< /ResourcePool >

< /project >
Adding error
TestExecContext method addError(String errorText, new WarningCaseArtifactsBuilder[]{..artifactBuilder1, ... artifactBuilderN..});
errorText - representation of error in lexical form.

WarningCaseArtifactsBuilder[] - array of artifact builders, which will build list of artifacts describing current error,
will be rendered on error report.

example:
Browser browser = (Browser) TestExecContextThreadLocal.getTestExecContext().getResource(new RequiredTestResource(Browser.class, ""));

BrowserArtifactsBuilder browserArtifactsBuilder = new BrowserArtifactsBuilder(browser, TestExecContextThreadLocal.getTestExecContext());
TestLogArtifactsBuilder testlogArtifactsBuilder = new TestLogArtifactsBuilder(TestExecContextThreadLocal.getTestExecContext());

getTestExecContext().addError(errorText, new WarningCaseArtifactsBuilder[]{ browserArtifactsBuilder, testlogArtifactsBuilder});
Adding captured state
TestExecContext method addCaptureEvent(String event, new WarningCaseArtifactsBuilder[]{..artifactBuilder1, ... artifactBuilderN..});
event - representation of current captured state in lexical form.

WarningCaseArtifactsBuilder[] - array of artifact builders, which will build list of artifacts describing current state,
will be rendered on error report.

example:
Browser browser = (Browser) TestExecContextThreadLocal.getTestExecContext().getResource(new RequiredTestResource(Browser.class, ""));
BrowserArtifactsBuilder browserArtifactsBuilder = new BrowserArtifactsBuilder(browser, TestExecContextThreadLocal.getTestExecContext());

getTestExecContext().addCaptureEvent(event, new WarningCaseArtifactsBuilder[]{browserArtifactsBuilder});
Adding metrics data
TestExecContext method addMetricValue("your_operation", new Date(), 1);
params are [String operation name, Date time, long value]

All added (time, value) pairs are grouped in lists by operation name
and can be viewed in graph rendered state on suite execution page (metrics graph report).

Usually it is used to log any performance data, like time of url load or any UI opeation,
current free memory status, CPU busy e.t.c, specially often is used after long load test to see any behaviour trends.
Accessing properties
Suite is started with defined properties file, containg list of "A=B" definitions.
Properties directory location is configured in bali.properties file

Properties props = TestExecContextThreadLocal.getTestExecContext().getSuiteExecContext().getProperties();
String a = props.getProperty("A");
Logging
Bali uses log4j for logging. It is configured from < TOMCAT_HOME >/conf/log4j.properties at webApp load.


public class ... {

protected static final Logger log = LogManager.getLogger(...class);

public void testDo() throws Exception {
log.info("positive success test, doing nothing");
}

}
Made on
Tilda