-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
18,488 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -5,10 +5,8 @@ on: | |
- master | ||
jobs: | ||
build: | ||
name: Build and Publish | ||
name: Build | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
|
@@ -21,9 +19,56 @@ jobs: | |
- name: Validate | ||
uses: pre-commit/[email protected] | ||
|
||
- name: Build project | ||
- uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Install playwright | ||
run: npx playwright install-deps | ||
|
||
- name: Build and Run Test Page | ||
run: | | ||
docker compose build | ||
docker compose up -d --wait | ||
- name: Build and Test | ||
run: ./gradlew clean build | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: jar | ||
path: build/libs/*.jar | ||
retention-days: 1 | ||
|
||
- name: Stop containers | ||
if: always() | ||
continue-on-error: true | ||
run: docker compose down -v | ||
|
||
publish: | ||
name: Publish | ||
runs-on: ubuntu-latest | ||
needs: build | ||
permissions: | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: "corretto" | ||
java-version: "17" | ||
cache: "gradle" | ||
|
||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: jar | ||
path: build/libs/ | ||
|
||
- name: Publish artefacts | ||
if: ${{ startsWith(github.ref, 'refs/tags/v') }} | ||
run: ./gradlew publish | ||
|
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
--- | ||
exclude: .key$ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
|
This file contains 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 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 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,12 @@ | ||
services: | ||
test-page: | ||
build: test-page | ||
image: "romanowalex/test-page:latest" | ||
container_name: test-page | ||
ports: | ||
- "8080:80" | ||
healthcheck: | ||
test: "curl --fail http://localhost || exit 1" | ||
interval: 5s | ||
timeout: 3s | ||
retries: 5 |
Binary file not shown.
This file contains 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 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,32 @@ | ||
package ru.romanow.playwright.pages | ||
|
||
import com.microsoft.playwright.Locator | ||
import com.microsoft.playwright.Page | ||
import com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat | ||
import org.assertj.core.api.Assertions.assertThat | ||
import ru.romanow.playwright.BaseComponent | ||
import ru.romanow.playwright.annotations.FindBy | ||
|
||
class MainPage(page: Page) : BaseComponent(page) { | ||
|
||
@FindBy(byTestId = "page-header") | ||
private lateinit var pageHeader: Locator | ||
|
||
@FindBy(byCss = "p[data-testid='description'] > ul > li") | ||
private lateinit var elements: Locator | ||
|
||
@FindBy(byXpath = "//p//li[last()]") | ||
private lateinit var lastElement: Locator | ||
|
||
fun assertFindByTestId(expected: String) { | ||
assertThat(pageHeader).hasText(expected) | ||
} | ||
|
||
fun assertFindByCss() { | ||
assertThat(elements.count()).isEqualTo(5) | ||
} | ||
|
||
fun assertFindByXpath() { | ||
assertThat(lastElement).containsText("parent") | ||
} | ||
} |
This file contains 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,22 @@ | ||
package ru.romanow.playwright.tests | ||
|
||
import com.microsoft.playwright.Page | ||
import com.microsoft.playwright.junit.UsePlaywright | ||
import org.junit.jupiter.api.Test | ||
import ru.romanow.playwright.ComponentFactory | ||
import ru.romanow.playwright.pages.MainPage | ||
import ru.romanow.playwright.utils.BrowserOptions | ||
|
||
@UsePlaywright(BrowserOptions::class) | ||
internal class PageTest { | ||
|
||
@Test | ||
fun test(page: Page) { | ||
page.navigate("/") | ||
val mainPage = ComponentFactory.create(page, MainPage::class) | ||
|
||
mainPage.assertFindByTestId("Тестовая страница") | ||
mainPage.assertFindByCss() | ||
mainPage.assertFindByXpath() | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/kotlin/ru/romanow/playwright/utils/BrowserOptions.kt
This file contains 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,22 @@ | ||
package ru.romanow.playwright.utils | ||
|
||
import com.microsoft.playwright.Browser.NewContextOptions | ||
import com.microsoft.playwright.BrowserType.LaunchOptions | ||
import com.microsoft.playwright.junit.Options | ||
import com.microsoft.playwright.junit.OptionsFactory | ||
import ru.romanow.playwright.utils.PropertiesHelper.Companion.get | ||
|
||
class BrowserOptions : OptionsFactory { | ||
override fun getOptions(): Options { | ||
return Options() | ||
.also { | ||
it.headless = get("headless-mode", Boolean::class) | ||
it.contextOptions = NewContextOptions().also { opt -> | ||
opt.baseURL = get("base-url") | ||
} | ||
it.launchOptions = LaunchOptions().also { opt -> | ||
opt.slowMo = if (get("slow-mode", Boolean::class) == true) 2000.0 else 0.0 | ||
} | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/kotlin/ru/romanow/playwright/utils/PropertiesHelper.kt
This file contains 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,67 @@ | ||
package ru.romanow.playwright.utils | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import java.util.* | ||
import kotlin.reflect.KClass | ||
|
||
class PropertiesHelper private constructor() { | ||
private var holder: MutableMap<String, String> | ||
|
||
init { | ||
val stream = object {}.javaClass.classLoader.getResourceAsStream("config.properties") | ||
stream.use { | ||
this.holder = HashMap<String, String>() | ||
val properties = Properties().also { p -> p.load(it) } | ||
val pattern = Regex("\\$\\{([^}]+)}") | ||
for (key in properties.keys) { | ||
var value = properties[key] as String | ||
var matcher = pattern.find(value) | ||
while (matcher != null) { | ||
val env = matcher.groups[1]!! | ||
var envValue = env.value | ||
envValue = if (envValue.contains(":")) { | ||
val parts = envValue.split(":".toRegex(), limit = 2) | ||
System.getenv(parts[0]) ?: parts[1] | ||
} else { | ||
System.getenv(envValue) ?: "" | ||
} | ||
value = pattern.replaceFirst(value, envValue) | ||
matcher = matcher.next() | ||
} | ||
holder[key.toString()] = value | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private val instance: PropertiesHelper by lazy { PropertiesHelper() } | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T : Any> get(key: String, cls: KClass<T>): T? { | ||
val value = instance.holder[key] | ||
return when (cls) { | ||
String::class -> value as T? | ||
Boolean::class -> value.toBoolean() as T? | ||
Int::class -> value?.toInt() as T? | ||
Double::class -> value?.toDouble() as T? | ||
else -> throw ClassCastException( | ||
"PropertyHolder supports only String, Integer, Double and Boolean types" | ||
) | ||
} | ||
} | ||
|
||
fun get(key: String): String? { | ||
return get(key, String::class) | ||
} | ||
} | ||
} | ||
|
||
internal class PropertiesHelperTest { | ||
|
||
@Test | ||
fun test() { | ||
assertThat(PropertiesHelper.get("test.base-url", String::class)).isEqualTo("http://localhost:8080") | ||
assertThat(PropertiesHelper.get("test.stop-on-error", Boolean::class)).isTrue | ||
} | ||
} |
This file contains 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,7 @@ | ||
base-url=${BASE_HOST:http://localhost}:${BASE_PORT:8080} | ||
headless-mode=${HEADLESS_MODE:true} | ||
slow-mode=${SLOW_MODE:true} | ||
|
||
# for test only | ||
test.base-url=${TEST_BASE_HOST:http://localhost}:${TEST_BASE_PORT:8080} | ||
test.stop-on-error=true |
Empty file.
This file contains 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,2 @@ | ||
/node_modules | ||
/build |
This file contains 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,11 @@ | ||
FROM node:18 AS builder | ||
WORKDIR /usr/src/app | ||
COPY package.json package-lock.json ./ | ||
RUN npm install | ||
COPY . ./ | ||
RUN npm run build | ||
|
||
FROM nginx:1.21-alpine | ||
COPY --from=builder /usr/src/app/build /usr/share/nginx/html | ||
EXPOSE 80 | ||
CMD ["nginx", "-g", "daemon off;"] |
Oops, something went wrong.