Skip to content

Commit

Permalink
Refactor Cucumber examples
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Nov 8, 2024
1 parent f82464f commit 023cd1f
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = "com.epam.reportportal.cucumber.ScenarioReporter",
features = "src/test/resources/features/attributes", glue = "com.epam.reportportal.example.cucumber6.attributes")
@CucumberOptions(
plugin = { "pretty", "html:report.html", "com.epam.reportportal.example.cucumber6.attributes.KeyValueAttributeReporter" },
features = "src/test/resources/features",
tags = "not @ignore",
glue = "com.epam.reportportal.example.cucumber6.glue")
public class BasicRunTest {
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.epam.reportportal.example.cucumber6.attributes;
package com.epam.reportportal.example.cucumber6.glue.attributes;

import com.epam.reportportal.annotations.attribute.Attribute;
import com.epam.reportportal.annotations.attribute.Attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
* limitations under the License.
*/

package com.epam.reportportal.example.cucumber6.logging;
package com.epam.reportportal.example.cucumber6.glue.logging;

import com.epam.reportportal.example.cucumber6.RunLoggingTest;
import com.epam.reportportal.example.cucumber6.BasicRunTest;
import com.epam.reportportal.service.Launch;
import com.epam.ta.reportportal.ws.model.launch.LaunchResource;
import io.cucumber.java.en.Given;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import retrofit2.HttpException;

import static java.util.Optional.ofNullable;

/**
* An example how to get and report current Launch ID, run {@link RunLoggingTest} class to see results.
* An example how to get and report current Launch ID, run {@link BasicRunTest} class to see results.
*/
public class LaunchIdLogging {
private static final Logger LOGGER = LoggerFactory.getLogger(LaunchIdLogging.class);
Expand All @@ -35,8 +36,22 @@ public class LaunchIdLogging {
public void logLaunchLink() {
ofNullable(Launch.currentLaunch()).ifPresent(l -> {
String launchUuid = l.getLaunch().blockingGet();
LaunchResource launchInfo = l.getClient().getLaunchByUuid(launchUuid).blockingGet();
LOGGER.info("Launch ID: {}", launchInfo.getLaunchId());
int tries = 0;
LaunchResource launchInfo = null;
do {
try {
launchInfo = l.getClient().getLaunchByUuid(launchUuid).blockingGet();
break;
} catch (HttpException e) {
LOGGER.error("Failed to get launch ID", e);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
}
} while (tries++ < 5);
LOGGER.info("Launch ID: {}", ofNullable(launchInfo).map(LaunchResource::getLaunchId).orElse(null));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package com.epam.reportportal.example.cucumber6.logging;
package com.epam.reportportal.example.cucumber6.glue.logging;

import com.epam.reportportal.example.cucumber6.RunLoggingTest;
import com.epam.reportportal.example.cucumber6.BasicRunTest;
import com.epam.reportportal.listeners.ListenerParameters;
import com.epam.reportportal.service.Launch;
import io.cucumber.java.en.Given;
Expand All @@ -26,7 +26,7 @@
import static java.util.Optional.ofNullable;

/**
* An example how to get and report current Launch URL, run {@link RunLoggingTest} class to see results.
* An example how to get and report current Launch URL, run {@link BasicRunTest} class to see results.
*/
public class LaunchUrlLogging {
private static final Logger LOGGER = LoggerFactory.getLogger(LaunchUrlLogging.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.epam.reportportal.example.cucumber6.selenium;
package com.epam.reportportal.example.cucumber6.glue.selenium;

import io.cucumber.java.After;
import io.cucumber.java.Before;
Expand All @@ -36,7 +36,7 @@ public class ScreenshotOnFailureHooks {

private WebDriver driver;

@Before
@Before("@selenium")
public void beforeScenario() {
driver = new ChromeDriver();
}
Expand All @@ -45,10 +45,11 @@ public void beforeScenario() {
public void test() {
driver.navigate().to("https://www.example.com");
LOGGER.warn("A failure test for demonstration, check out 'After hooks' for the failure screenshot");
Assert.assertEquals("Google", driver.getTitle());
String envTitle = System.getenv("RP_EXPECTED_TITLE");
Assert.assertEquals(envTitle == null ? "Google" : envTitle, driver.getTitle());
}

@After
@After("@selenium")
public void afterScenario(Scenario scenario) {
takeScreenshot(scenario);
driver.quit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Feature: Screenshot reporting

@selenium
Scenario: Screenshot
Given I report scenario with screenshot

0 comments on commit 023cd1f

Please sign in to comment.