Search in sources :

Example 1 with Element

use of org.utils.ShareDataTest.Element in project selenium_java by sergueik.

the class ShareDataTest method beforeMethod.

@BeforeMethod
public void beforeMethod(Method method, ITestResult testresult) {
    // alternative: ITestContext context
    // super.beforeMethod(method, testresult);
    Inject inject = method.getAnnotation(Inject.class);
    if (inject != null) {
        Element data = new Element("//", 1);
        testresult.setAttribute("element", data);
    }
}
Also used : Element(org.utils.ShareDataTest.Element) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with Element

use of org.utils.ShareDataTest.Element in project selenium_java by sergueik.

the class ShareDataTest method dataConsumingTest.

@Test
@Inject
public void dataConsumingTest() {
    ITestResult testresult = Reporter.getCurrentTestResult();
    Object data = testresult.getAttribute("element");
    if (data instanceof Element) {
        Assert.assertNotNull(((Element) data).getName(), "Data element must provide the name");
        Assert.assertTrue(((Element) data).getCount() != 0, "Data element must provide nonzero count");
    }
}
Also used : ITestResult(org.testng.ITestResult) Element(org.utils.ShareDataTest.Element) Test(org.testng.annotations.Test)

Aggregations

Element (org.utils.ShareDataTest.Element)2 ITestResult (org.testng.ITestResult)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1