-
Notifications
You must be signed in to change notification settings - Fork 0
AUT-6940 helper class migration into OSS repo #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
auto-sdk-java-helpers/src/main/java/com/applause/auto/helpers/allure/AllureDriverUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * | ||
| * Copyright © 2025 Applause App Quality, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
| package com.applause.auto.helpers.allure; | ||
|
|
||
| import io.qameta.allure.Allure; | ||
| import java.io.ByteArrayInputStream; | ||
| import lombok.NonNull; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.openqa.selenium.OutputType; | ||
| import org.openqa.selenium.TakesScreenshot; | ||
| import org.openqa.selenium.WebDriver; | ||
|
|
||
| /** Provides utility methods for attaching information to Allure reports. */ | ||
| public final class AllureDriverUtils { | ||
|
|
||
| private static final Logger LOGGER = LogManager.getLogger(AllureDriverUtils.class); | ||
| private static final String SCREENSHOT_ATTACHMENT = "Screenshot attachment"; | ||
| private static final String IMAGE_PNG = "image/png"; | ||
| private static final String CURRENT_URL = "Current URL"; | ||
| private static final String TEXT_PLAIN = "text/plain"; | ||
| private static final String CURRENT_PAGE_SOURCE = "Current page source"; | ||
| private static final String LOG_EXTENSION = ".log"; | ||
|
|
||
| private AllureDriverUtils() { | ||
| // Utility class - no public constructor | ||
| } | ||
|
|
||
| /** | ||
| * Attaches a screenshot to the Allure report. | ||
| * | ||
| * @param driver The WebDriver instance to capture the screenshot from. | ||
| */ | ||
| public static void attachScreenshot(@NonNull final WebDriver driver) { | ||
| LOGGER.info("Taking screenshot on test failure"); | ||
| try { | ||
| var screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); | ||
| Allure.addAttachment( | ||
| SCREENSHOT_ATTACHMENT, IMAGE_PNG, new ByteArrayInputStream(screenshot), "png"); | ||
| } catch (Exception e) { | ||
| LOGGER.error("Error taking screenshot: {}", e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Attaches the current URL to the Allure report. | ||
| * | ||
| * @param driver The WebDriver instance to get the current URL from. | ||
| */ | ||
| public static void attachCurrentURL(@NonNull final WebDriver driver) { | ||
| LOGGER.info("Attaching current URL"); | ||
| try { | ||
| Allure.addAttachment(CURRENT_URL, TEXT_PLAIN, driver.getCurrentUrl(), LOG_EXTENSION); | ||
| } catch (Exception e) { | ||
| LOGGER.error("Error taking current URL: {}", e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Attaches the current page source to the Allure report. | ||
| * | ||
| * @param driver The WebDriver instance to get the page source from. | ||
| */ | ||
| public static void attachCurrentPageSourceOnFailure(@NonNull final WebDriver driver) { | ||
| LOGGER.info("Attaching page source"); | ||
| try { | ||
| Allure.addAttachment(CURRENT_PAGE_SOURCE, TEXT_PLAIN, driver.getPageSource(), LOG_EXTENSION); | ||
| } catch (Exception e) { | ||
| LOGGER.error("Error taking current page source: {}", e.getMessage()); | ||
| } | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
auto-sdk-java-helpers/src/main/java/com/applause/auto/helpers/allure/AllureUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * | ||
| * Copyright © 2025 Applause App Quality, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
| package com.applause.auto.helpers.allure; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import lombok.NonNull; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| /** Utility class for Allure reporting. */ | ||
| public final class AllureUtils { | ||
|
|
||
| private static final Logger logger = LogManager.getLogger(AllureUtils.class); | ||
| private static final String CATEGORIES_JSON = "categories.json"; | ||
|
|
||
| private AllureUtils() {} | ||
|
|
||
| /** | ||
| * Copies the Allure defects categorization JSON file to the Allure report directory. | ||
| * | ||
| * @param allureReportPath The path to the Allure report directory. | ||
| * @param allureDefectsCategorisationFilePath The path to the Allure defects categorization JSON | ||
| * file. | ||
| * @throws IOException If an I/O error occurs. | ||
| */ | ||
| public static void addAllureDefectsCategoriesConfiguration( | ||
| @NonNull final String allureReportPath, | ||
| @NonNull final String allureDefectsCategorisationFilePath) | ||
| throws IOException { | ||
|
|
||
| logger.info("Copying defects configs to {} file for Allure", CATEGORIES_JSON); | ||
|
|
||
| final Path categoriesAllureFile = Path.of(allureReportPath, CATEGORIES_JSON); | ||
|
|
||
| if (!Files.exists(categoriesAllureFile)) { | ||
| Files.createFile(categoriesAllureFile); | ||
| } | ||
|
|
||
| Files.copy(Path.of(allureDefectsCategorisationFilePath), categoriesAllureFile); | ||
| } | ||
| } |
103 changes: 103 additions & 0 deletions
103
...rs/src/main/java/com/applause/auto/helpers/allure/appenders/AllureLogsToStepAppender.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * | ||
| * Copyright © 2025 Applause App Quality, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
| package com.applause.auto.helpers.allure.appenders; | ||
|
|
||
| import io.qameta.allure.Allure; | ||
| import java.io.Serializable; | ||
| import java.util.Arrays; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentSkipListSet; | ||
| import org.apache.logging.log4j.core.*; | ||
| import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
| import org.apache.logging.log4j.core.config.Node; | ||
| import org.apache.logging.log4j.core.config.plugins.Plugin; | ||
| import org.apache.logging.log4j.core.config.plugins.PluginAttribute; | ||
| import org.apache.logging.log4j.core.config.plugins.PluginElement; | ||
| import org.apache.logging.log4j.core.config.plugins.PluginFactory; | ||
| import org.apache.logging.log4j.core.layout.PatternLayout; | ||
|
|
||
| /** Appender for logging to Allure steps. */ | ||
| @Plugin( | ||
| name = "AllureLogsToStepAppender", | ||
| category = Node.CATEGORY, | ||
| elementType = Appender.ELEMENT_TYPE) | ||
| public final class AllureLogsToStepAppender extends AbstractAppender { | ||
|
|
||
| private static final String COMMA = ","; | ||
| private static final Set<String> FILTERED_PACKAGES_TO_APPEND_SET = new ConcurrentSkipListSet<>(); | ||
|
|
||
| private AllureLogsToStepAppender( | ||
| final String name, | ||
| final Filter filter, | ||
| final Layout<? extends Serializable> layout, | ||
| final boolean ignoreExceptions) { | ||
| super(name, filter, layout, ignoreExceptions, null); | ||
| } | ||
|
|
||
| /** | ||
| * Creates an AllureLogsToStepAppender. | ||
| * | ||
| * @param name The name of the appender. | ||
| * @param layout The layout to use for the appender. | ||
| * @param filter The filter to use for the appender. | ||
| * @param filteredPackagesToAppend A comma-separated list of packages to filter. | ||
| * @return A new AllureLogsToStepAppender instance, or null if the name is null. | ||
| */ | ||
| @PluginFactory | ||
| public static AllureLogsToStepAppender createAppender( | ||
| @PluginAttribute("name") final String name, | ||
| @PluginElement("Layout") final Layout<? extends Serializable> layout, | ||
| @PluginElement("Filter") final Filter filter, | ||
| @PluginAttribute("filteredPackagesToAppend") final String filteredPackagesToAppend) { | ||
|
|
||
| if (name == null) { | ||
| return null; | ||
| } | ||
|
|
||
| final var usedLayout = Objects.requireNonNullElse(layout, PatternLayout.createDefaultLayout()); | ||
|
|
||
| if (filteredPackagesToAppend != null) { | ||
| FILTERED_PACKAGES_TO_APPEND_SET.addAll(Arrays.asList(filteredPackagesToAppend.split(COMMA))); | ||
| } | ||
|
|
||
| return new AllureLogsToStepAppender(name, filter, usedLayout, true); | ||
| } | ||
|
|
||
| /** | ||
| * Appends a log event to Allure step. | ||
| * | ||
| * @param event The log event to append. | ||
| */ | ||
| @Override | ||
| public void append(final LogEvent event) { | ||
| if (isSourcePackageValidForAppender(event)) { | ||
| Allure.step(event.getMessage().getFormattedMessage()); | ||
| } | ||
| } | ||
|
|
||
| private boolean isSourcePackageValidForAppender(final LogEvent event) { | ||
| if (FILTERED_PACKAGES_TO_APPEND_SET.isEmpty()) { | ||
| return true; | ||
| } | ||
|
|
||
| final var sourceClassName = event.getSource().getClassName(); | ||
|
|
||
| return FILTERED_PACKAGES_TO_APPEND_SET.stream().anyMatch(sourceClassName::contains); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.