All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.jenkins.results.parser.PlaywrightPortalTestBatch Maven / Gradle / Ivy

There is a newer version: 1.0.1492
Show newest version
/**
 * SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

package com.liferay.jenkins.results.parser;

import java.io.File;
import java.io.IOException;

import java.util.Map;

/**
 * @author Michael Hashimoto
 */
public class PlaywrightPortalTestBatch
	extends BasePortalTestBatch {

	@Override
	public void run() {
		try {
			executeBatch();
		}
		catch (AntException antException) {
			throw new RuntimeException(antException);
		}
		finally {
			publishResults();

			publishPlaywrightReport();
		}
	}

	protected PlaywrightPortalTestBatch(
		PortalBatchBuildData portalBatchBuildData, Workspace workspace) {

		super(portalBatchBuildData, workspace);
	}

	@Override
	protected Map getEnvironmentVariables() {
		Map environmentVariables =
			super.getEnvironmentVariables();

		PortalBatchBuildData portalBatchBuildData = getBatchBuildData();

		TopLevelBuildData topLevelBuildData =
			portalBatchBuildData.getTopLevelBuildData();

		String portalBatchTestSelector = topLevelBuildData.getBuildParameter(
			"PORTAL_BATCH_TEST_SELECTOR");

		if (!JenkinsResultsParserUtil.isNullOrEmpty(portalBatchTestSelector)) {
			environmentVariables.put(
				"PLAYWRIGHT_PROJECT_NAME", portalBatchTestSelector);
		}

		return environmentVariables;
	}

	protected void publishPlaywrightReport() {
		File playwrightReportFile = new File(
			getPrimaryPortalWorkspaceDirectory(),
			"modules/test/playwright/playwright-report/index.html");

		if (!playwrightReportFile.exists()) {
			return;
		}

		PortalBatchBuildData portalBatchBuildData = getBatchBuildData();

		try {
			JenkinsResultsParserUtil.copy(
				playwrightReportFile.getParentFile(),
				new File(
					portalBatchBuildData.getArtifactDir(),
					"playwright-reports"));
		}
		catch (IOException ioException) {
			throw new RuntimeException(ioException);
		}

		StringBuilder sb = new StringBuilder();

		sb.append(portalBatchBuildData.getPortalBranchSHA());
		sb.append(" - ");
		sb.append(portalBatchBuildData.getBatchName());
		sb.append(" - ");
		sb.append("Jenkins Report - ");
		sb.append("Playwright Report");

		sb.append("
    "); for (String test : portalBatchBuildData.getTestList()) { sb.append("
  • "); sb.append(test); sb.append("
  • "); } sb.append("
"); portalBatchBuildData.setBuildDescription(sb.toString()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy