-
Notifications
You must be signed in to change notification settings - Fork 4
playwright module unit tests #80
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
base: develop
Are you sure you want to change the base?
Changes from 8 commits
683f4a4
91080e1
ed01033
30548d2
77d6f6c
6dcbdea
4098dfe
2057580
faac50e
2b1c4a6
39348c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.capgemini.mrchecker.playwright.core.pages; | ||
|
|
||
| import com.capgemini.mrchecker.playwright.core.BasePage; | ||
|
|
||
| public class TestPage extends BasePage { | ||
| @Override | ||
| public boolean isLoaded() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void load() { | ||
| loadPage("https://google.com/"); | ||
| } | ||
|
|
||
| @Override | ||
| public String pageTitle() { | ||
| return getActualPageTitle(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.capgemini.mrchecker.playwright.core.newDrivers; | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double newline, please use formatter |
||
| import org.junit.jupiter.api.*; | ||
|
|
||
| import com.capgemini.mrchecker.playwright.core.base.properties.PropertiesPlaywright; | ||
| import com.capgemini.mrchecker.playwright.tags.UnitTest; | ||
| import com.capgemini.mrchecker.test.core.base.properties.PropertiesSettingsModule; | ||
| import com.google.inject.Guice; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| @UnitTest | ||
| public class DriverManagerTest { | ||
| private DriverManager driverManager; | ||
|
|
||
| @BeforeAll | ||
| public static void setUpBeforeClass() { | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void tearDownAfterClass() { | ||
| } | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| PropertiesPlaywright propertiesPlaywright = Guice.createInjector(PropertiesSettingsModule.init()) | ||
| .getInstance(PropertiesPlaywright.class); | ||
|
|
||
| driverManager = new DriverManager(propertiesPlaywright); | ||
| driverManager.start(); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() { | ||
| driverManager.stop(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldDriverBeCreated() { | ||
| assertTrue(DriverManager.wasDriverCreated(), "Driver was not created"); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.capgemini.mrchecker.playwright.tags; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import org.junit.jupiter.api.Tag; | ||
|
|
||
| @Target(ElementType.TYPE) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Tag("UnitTest") | ||
| public @interface UnitTest { | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline at EOF |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.capgemini.mrchecker.playwright.unit; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.capgemini.mrchecker.playwright.core.pages.TestPage; | ||
| import com.capgemini.mrchecker.playwright.tags.UnitTest; | ||
| import com.capgemini.mrchecker.test.core.BaseTest; | ||
| import com.capgemini.mrchecker.test.core.utils.PageFactory; | ||
|
|
||
| @UnitTest | ||
| class BasePageTest extends BaseTest { | ||
|
|
||
| @Test | ||
| void testGetPageTitle() { | ||
| TestPage testPage = PageFactory.getPageInstance(TestPage.class); | ||
| testPage.load(); | ||
| Assertions.assertEquals("Google", testPage.pageTitle(), "Wrong page title"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.capgemini.mrchecker.playwright.unit; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import org.junit.jupiter.api.*; | ||
| import org.junit.jupiter.api.parallel.ResourceLock; | ||
|
|
||
| import com.capgemini.mrchecker.playwright.core.newDrivers.DriverManager; | ||
| import com.capgemini.mrchecker.playwright.core.pages.TestPage; | ||
| import com.capgemini.mrchecker.playwright.tags.UnitTest; | ||
| import com.capgemini.mrchecker.test.core.utils.PageFactory; | ||
|
|
||
| @UnitTest | ||
| @ResourceLock(value = "SingleThread") | ||
| public class DefaultDriverBrowserTest { | ||
| @BeforeAll | ||
| public static void setUpBeforeClass() { | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void tearDownAfterClass() { | ||
| } | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
|
|
||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() { | ||
| } | ||
|
|
||
| @Test | ||
| public void testParameterGetChrome() { | ||
| TestPage testPage = PageFactory.getPageInstance(TestPage.class); | ||
| testPage.load(); | ||
| String driverName = DriverManager.getDriver() | ||
| .browser() | ||
| .browserType() | ||
| .name(); | ||
| assertEquals("chromium", driverName, "Wrong browser name"); | ||
| } | ||
|
|
||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline at EOF |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.capgemini.mrchecker.playwright.unit; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.capgemini.mrchecker.playwright.core.newDrivers.NewPlaywright; | ||
| import com.capgemini.mrchecker.playwright.tags.UnitTest; | ||
| import com.microsoft.playwright.Browser; | ||
| import com.microsoft.playwright.Playwright; | ||
|
|
||
| @UnitTest | ||
| public class NewPlaywrightBrowsersTest { | ||
| private final NewPlaywright playwright = new NewPlaywright(Playwright.create()); | ||
|
|
||
| @Test | ||
| public void shouldBrowserNameBeFirefox() { | ||
| Browser browser = playwright.firefox() | ||
| .launch(); | ||
| assertEquals("firefox", browser.browserType() | ||
| .name(), "Wrong browser name"); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldBrowserNameBeChromium() { | ||
| Browser browser = playwright.chromium() | ||
| .launch(); | ||
| assertEquals("chromium", browser.browserType() | ||
| .name(), "Wrong browser name"); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldBrowserNameBeWebkit() { | ||
| Browser browser = playwright.webkit() | ||
| .launch(); | ||
| assertEquals("webkit", browser.browserType() | ||
| .name(), "Wrong browser name"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| package com.capgemini.mrchecker.playwright.unit.base.runtime; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.core.Is.is; | ||
| import static org.hamcrest.core.IsEqual.equalTo; | ||
| import static org.hamcrest.core.IsInstanceOf.instanceOf; | ||
| import static org.hamcrest.core.IsNull.nullValue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.parallel.ResourceLock; | ||
|
|
||
| import com.capgemini.mrchecker.playwright.core.base.runtime.RuntimeParametersPlaywright; | ||
|
|
||
| @ResourceLock(value = "SingleThread") | ||
| public class RuntimeParametersTest { | ||
|
|
||
| private static final Map<String, String> STARTUP_PARAMETERS_VALUES = new LinkedHashMap<String, String>() { | ||
| { | ||
| put("browser", "chromedriver"); | ||
| put("browserVersion", "11.0"); | ||
| put("seleniumGrid", "something"); | ||
| put("os", "linux"); | ||
| put("browserOptions", | ||
| "headless;window-size=1200x600;testEquals=FirstEquals=SecondEquals;--testMe;acceptInsecureCerts=true;maxInstances=3"); | ||
| put("headless", "false"); | ||
| } | ||
| }; | ||
|
|
||
| public static final String DEFAULT_BROWSER_VALUE = "chrome"; | ||
| public static final String BROWSER_OPTIONS_TEST_KEY = "browserOptionsTestKey"; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| STARTUP_PARAMETERS_VALUES.forEach(System::setProperty); | ||
| refreshAllParameters(); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() { | ||
| STARTUP_PARAMETERS_VALUES.forEach((k, v) -> System.clearProperty(k)); | ||
| refreshAllParameters(); | ||
| } | ||
|
|
||
| private static void refreshAllParameters() { | ||
| doForEachParam(RuntimeParametersPlaywright::refreshParameterValue); | ||
| } | ||
|
|
||
| private static void doForEachParam(Consumer<RuntimeParametersPlaywright> applyFunction) { | ||
| Arrays.stream(RuntimeParametersPlaywright.values()) | ||
| .forEach(applyFunction); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetAllStartupProperties() { | ||
| doForEachParam((e) -> assertThat(e.toString() + " failed!", e.getValue(), is(equalTo(STARTUP_PARAMETERS_VALUES.get(e.getKey()))))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetReturnOriginBrowserValue() { | ||
| System.setProperty("browser", STARTUP_PARAMETERS_VALUES.get("browser")); | ||
|
|
||
| refreshAllParameters(); | ||
| String browserValue = RuntimeParametersPlaywright.BROWSER.getValue(); | ||
|
|
||
| assertThat(browserValue, is(equalTo(STARTUP_PARAMETERS_VALUES.get(RuntimeParametersPlaywright.BROWSER.getKey())))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetReturnDefaultBrowserValue() { | ||
| Arrays.stream(new String[] { "", "null" }) | ||
| .forEach((s) -> { | ||
| System.setProperty("browser", s); | ||
|
|
||
| refreshAllParameters(); | ||
| String browserValue = RuntimeParametersPlaywright.BROWSER.getValue(); | ||
|
|
||
| assertThat("Failed for '" + s + "'!", browserValue, is(equalTo(DEFAULT_BROWSER_VALUE))); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetReturnDefaultBrowserValueWhenNoSystemProperty() { | ||
| System.clearProperty("browser"); | ||
|
|
||
| refreshAllParameters(); | ||
| String browserValue = RuntimeParametersPlaywright.BROWSER.getValue(); | ||
|
|
||
| assertThat(browserValue, is(equalTo(DEFAULT_BROWSER_VALUE))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldBrowserOptionBeBoolean() { | ||
| shouldBrowserOptionBeOfClass("true", Boolean.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldBrowserOptionBeInteger() { | ||
| shouldBrowserOptionBeOfClass("123", Integer.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldBrowserOptionBeIntegerFloat() { | ||
| shouldBrowserOptionBeOfClass("123.321", Float.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldBrowserOptionBeIntegerString() { | ||
| shouldBrowserOptionBeOfClass("blue", String.class); | ||
| } | ||
|
|
||
| private void shouldBrowserOptionBeOfClass(String value, Class<?> clazz) { | ||
| System.setProperty("browserOptions", BROWSER_OPTIONS_TEST_KEY + "=" + value); | ||
|
|
||
| refreshAllParameters(); | ||
| Map<String, Object> browserOptionsValues = RuntimeParametersPlaywright.BROWSER_OPTIONS.getValues(); | ||
| Object optionValue = browserOptionsValues.get(BROWSER_OPTIONS_TEST_KEY); | ||
|
|
||
| assertThat(optionValue, is(instanceOf(clazz))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetProperBrowserOptionsValuesSize() { | ||
| final String[] browserOptions = STARTUP_PARAMETERS_VALUES.get(RuntimeParametersPlaywright.BROWSER_OPTIONS.getKey()) | ||
| .split(";"); | ||
|
|
||
| int browserOptionsCount = RuntimeParametersPlaywright.BROWSER_OPTIONS.getValues() | ||
| .size(); | ||
|
|
||
| assertThat(browserOptionsCount, is(equalTo(browserOptions.length))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetProperBrowserOptionsValuesContents() { | ||
| final String[] browserOptions = STARTUP_PARAMETERS_VALUES.get(RuntimeParametersPlaywright.BROWSER_OPTIONS.getKey()) | ||
| .split(";"); | ||
|
|
||
| Map<String, Object> browserOptionsValues = RuntimeParametersPlaywright.BROWSER_OPTIONS.getValues(); | ||
|
|
||
| browserOptionsValues.forEach((key, value) -> { | ||
| try { | ||
| String browserOption = Arrays.stream(browserOptions) | ||
| .filter(s -> s.startsWith(key)) | ||
| .findFirst() | ||
| .orElseThrow(Exception::new); | ||
|
|
||
| assertThat(browserOption.endsWith(value.toString()), is(equalTo(true))); | ||
| } catch (Exception e) { | ||
| fail(key + " does NOT exist"); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldGetProperBrowserOptionsValuesBeNull() { | ||
| Map<String, Object> browserOptionsValues = RuntimeParametersPlaywright.BROWSER.getValues(); | ||
|
|
||
| assertThat(browserOptionsValues, is(nullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldToStringReturnKeyValue() { | ||
| String toStringValue = RuntimeParametersPlaywright.BROWSER.toString(); | ||
|
|
||
| assertThat(toStringValue, is(equalTo("browser=" + STARTUP_PARAMETERS_VALUES.get("browser")))); | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline at EOF |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| allure.results.directory=target/allure-results | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline at EOF |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| junit.jupiter.extensions.autodetection.enabled=true | ||
| junit.jupiter.execution.parallel.enabled=true | ||
| #junit.jupiter.execution.parallel.mode.default=concurrent | ||
| junit.jupiter.execution.parallel.mode.default=same_thread | ||
| junit.jupiter.execution.parallel.mode.classes.default=concurrent | ||
| #junit.jupiter.execution.parallel.mode.classes.default=same_thread | ||
| junit.jupiter.execution.parallel.config.strategy=dynamic | ||
| junit.jupiter.execution.parallel.config.dynamic.factor=1 | ||
| cucumber.ansi-colors.disabled=false | ||
| cucumber.publish.quiet=true | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline at EOF |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this change? Are tests fail if you leave it assigned empty?