TestProject Forum
Powered by leading experts in the test automation community

Utils methods are displayed as tests in the Report

Hi, i started a POC with TestProject. I have a framework to run iOS Automated test based in Java, TestNg and Appium. But when i run a test with the driver of test project my utils methods are taken as tests. For example i have a method to start the capabilities with a TestNG annotation:

@Parameters ({ “platformVersion”, “udid”, “deviceName”, “wdaPort”, “hub” })

@BeforeTest (alwaysRun = true)

public void AbrirApp( @Optional (DefaultDevice. PLATFORM_VERSION ) String platformVersion,

@Optional (DefaultDevice. UDID ) String udid, @Optional (DefaultDevice. DEVICE_NAME ) String deviceName,

@Optional (DefaultDevice. WDA_PORT ) String wdaPort, @Optional (DefaultDevice. HUB ) String hub)

throws IOException, TimeoutException {

NewLogger. info ("@BeforeTest - Setting Capabilities - Thread: " + Thread. currentThread ().getId());

capabilities = new DesiredCapabilities();

capabilities.setCapability(“udid”, udid);

capabilities.setCapability(“platformVersion”, platformVersion);

capabilities.setCapability(“deviceName”, deviceName);

capabilities.setCapability(“wdaLocalPort”, wdaPort);

capabilities.setCapability(“platformName”, “iOS”);

capabilities.setCapability(“bundleId”, BUNDLE_ID );

capabilities.setCapability(“automationName”, “XCUITest”);

capabilities.setCapability(“xcodeSigningId”, “iPhone Developer”);

capabilities.setCapability(“xcodeOrgId”, “6X3RBUEYFB”);

capabilities.setCapability(“noReset”, false);

capabilities.setCapability(“autoAcceptAlerts”, true);

capabilities.setCapability(“useNewWDA”, true);

// Se agrega por Thread Sleep > 60 en test de Amplitude

capabilities.setCapability(“newCommandTimeout”, 80);

driver = new IOSDriver(new URL(hub), capabilities);

ThreadLocalDriver. setTLDriver (driver);

}

This is only one, i have methods called beforeClass and BeforeMethod, also shown in the reports. Anyone have the same issue?

Hi @pablo.slaj, can you please upload the file of the test itself? and what do you mean by “taken as tests”? you see those steps in the reporter as tests?

Hi!, sorry for my english. Yes, i mean this methods are displayed in the report as an executed test.
This is a part of a Class where there are a lot of test, there you will see another util method also present in the report beforeMethod().

package tests.markets;

import java.util.Hashtable;

import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import io.appium.java_client.MobileElement;
import pages.*;
import tests.base.BaseClass;
import utils.ExcelDataProvider;
import utils.actions.Direction;

@Listeners(utils.listeners.ExtentListeners.class)
@Test(groups = { “basket” })
public class Basket extends BaseClass {

private HomePage homePage;
private HomeGlobalSearchPage homeGlobalSearchPage;
private CPGsGlobalSearchPage cpgsGlobalSearchPage;
private AddressSelectionPage addressSelectionPage;
private CPGsHomePage cpgsHomePage;
private BasketPage basketPage;
private StorePage storePage;
private ProductDetailsPage productDetailsPage;
private SubCorridorGridPage subCorridorGridPage;
private SubcorridorPage subCorridorPage;
private StoreSearchPage storeSearchPage;

@BeforeMethod
public void beforeMethod() {
	homePage = new HomePage();
}

@Test(dataProvider = "dpGoogleApi", dataProviderClass = ExcelDataProvider.class)
public void t_AddProdU_Basket(Hashtable<String, String> data) {

	// Seleccionamos la direccion
	homePage.selectAddress(data.get("Address"));

	// Entrar en Mercados:
	cpgsHomePage = homePage.clickOnMercados();
	homePage.handleAddress(data.get("Address"));
	cpgsHomePage.handleCompraGrande();

	// Buscamos la tienda:
	storePage = cpgsHomePage.searchAndClickStore(data.get("Store_ID"));

	// Validamos que la canasta este vacia:
	storePage.deleteProductsFromBasket();

	// Buscamos el corredor y el producto
	storePage.scrollToFindProductInCorridor(data.get("Corridor_Name"), data.get("Product_ID"), 20, 4);

	// Buscamos el producto deseado
	productDetailsPage = storePage.clickOnProduct(data.get("Product_ID"));

	// Añadimos el producto a la canasta
	productDetailsPage.clickOnConfirm();

	// Validamos que el producto haya sido añadido correctamente
	basketPage = storePage.clickOnBasket();
	basketPage.assertProductInfoBasket(data.get("Product_ID"));

}

Sorry for the delay, we did some investigating.
TestNG runs the BeforeMethod and AfterMethod in a different scope than the Test. openSDK reports steps automatically, so it seems the reporter receives a report from different annotations and separate them.
We will continue our investigation and will let you know.

In the mean time you can enable and disable the auto report in beforeMethod(). I’m assuming you have access to the driver instance in HomePage, add there a method disableTestAutoReports(boolean)

public void disableTestAutoReports(boolean disable) {
    driver.report().disableTestAutoReports(disable);
}

And call it from beforeMethod()

@BeforeMethod
public void beforeMethod() {
    homePage.disableTestAutoReports(true);
	homePage = new HomePage();
    homePage.disableTestAutoReports(false);
}

If you have more options in beforeMethod() create base class to the page objects and add the new method there.

1 Like

Thanks! this works! :slight_smile: