Skip to content

Commit

Permalink
run idea for UI tests from test process
Browse files Browse the repository at this point in the history
  • Loading branch information
nizienko committed Mar 5, 2024
1 parent d2a2ce6 commit e0c9234
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/runUiTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ jobs:
matrix:
include:
- os: ubuntu-latest
runIde: |
prepareUI: |
export DISPLAY=:99.0
Xvfb -ac :99 -screen 0 1920x1080x24 &
sleep 10
mkdir -p build/reports
./gradlew :runIdeForUiTests > build/reports/idea.log &
runTests: |
export DISPLAY=:99.0
./gradlew :test
Expand All @@ -41,26 +40,21 @@ jobs:
- name: Clean
run: ./gradlew :clean

- name: Run Idea
run: ${{ matrix.runIde }}

- name: Wait for Idea started
uses: jtalk/url-health-check-action@v3
with:
url: ${{ matrix.url }}
max-attempts: 15
retry-delay: 30s
- name: Prepare UI
run: ${{ matrix.prepareUI }}

- name: Run tests
run: ${{ matrix.runTests }}

- name: Move video
if: ${{ failure() }}
run: mv video build/reports

- name: Wait for reports
uses: jakejarvis/wait-action@master
with:
time: '10s'

- name: Save reports
uses: actions/upload-artifact@v3
with:
Expand Down
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import com.intellij.openapi.wm.WindowManager
import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager
import java.io.InputStreamReader
import java.nio.charset.StandardCharsets
import java.util.*
import java.util.concurrent.CountDownLatch
import kotlin.text.Regex.Companion.escapeReplacement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package com.github.nizienko.propertiesSwitcher.actions

import com.github.nizienko.propertiesSwitcher.PropertySwitcherService
import com.github.nizienko.propertiesSwitcher.fileType.PropertiesTemplateFileType
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.LangDataKeys
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.components.service
import com.intellij.openapi.fileEditor.FileDocumentManager

Expand All @@ -20,6 +17,10 @@ internal class ReloadPropertyTemplatesAction : AnAction() {
service.reload()
}

override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}

override fun update(event: AnActionEvent) {
val virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE)
val presentation = event.presentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package com.github.nizienko.propertiesSwitcher.actions
import com.github.nizienko.propertiesSwitcher.Prop
import com.github.nizienko.propertiesSwitcher.SwitchablePropertyFile
import com.github.nizienko.propertiesSwitcher.switcher
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.ui.popup.PopupStep
import com.intellij.openapi.ui.popup.util.BaseListPopupStep
import com.intellij.vcs.commit.NonModalCommitPanel.Companion.showAbove
import java.awt.Component
import javax.swing.JComponent

internal class SwitchPropertiesAction : AnAction() {
Expand All @@ -26,6 +26,10 @@ internal class SwitchPropertiesAction : AnAction() {
}
}

override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}

override fun update(e: AnActionEvent) {
super.update(e)
}
Expand Down
46 changes: 42 additions & 4 deletions src/test/kotlin/CreateSwitchPropertiesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@ import com.intellij.remoterobot.steps.CommonSteps
import com.intellij.remoterobot.stepsProcessing.step
import com.intellij.remoterobot.utils.keyboard
import com.intellij.remoterobot.utils.waitFor
import com.intellij.remoterobot.utils.waitForIgnoringError
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import java.io.BufferedReader
import java.io.InputStreamReader
import java.time.Duration
import kotlin.concurrent.thread

class CreateSwitchPropertiesTest {
companion object {
private val robot = RemoteRobot("http://127.0.0.1:8082")
private val steps = CommonSteps(robot)

@JvmStatic
@BeforeAll
fun beforeAll() {
robot.runIde()
}

@JvmStatic
@AfterAll
fun afterAll(): Unit {
fun afterAll() {
steps.invokeAction("Exit")
robot.idea {
find<ContainerFixture>(byXpath("//div[@class='MyDialog']"))
Expand Down Expand Up @@ -78,6 +89,16 @@ class CreateSwitchPropertiesTest {
""".trimIndent()
)
step("Add third parameter") {
textEditor().editor.clickOnOffset(textEditor().editor.text.length)
keyboard {
backspace()
enterText(" # comment")
enter()
enterText("property_3=value_1")
enter()
}
}

step("Switch properties") {
widget().click()
Expand All @@ -90,7 +111,8 @@ class CreateSwitchPropertiesTest {
assert(
textEditor().editor.text == """
property_1=value_1
property_2=value_3
property_2=value_3 # comment
property_3=value_1
""".trimIndent()
)
Expand All @@ -106,7 +128,8 @@ class CreateSwitchPropertiesTest {
assert(
textEditor().editor.text == """
property_1=value_1
property_2=value_2
property_2=value_2 # comment
property_3=value_1
""".trimIndent()
)
Expand All @@ -133,4 +156,19 @@ private fun ContainerFixture.popup(): ContainerFixture {
}

private fun CommonContainerFixture.widget(): ComponentFixture =
component(byXpath("//div[@class='IdeStatusBarImpl']//div[@class='TextPresentationComponent']"))
component(byXpath("//div[@class='IdeStatusBarImpl']//div[@class='TextPresentationComponent']"))

private fun RemoteRobot.runIde() {
thread {
val process = Runtime.getRuntime().exec("./gradlew :runIdeForUiTests")
val reader = BufferedReader(InputStreamReader(process.inputStream))
var line: String?
while (reader.readLine().also { line = it } != null) {
println(line)
}
}
waitForIgnoringError(Duration.ofSeconds(120)) {
findAll(CommonContainerFixture::class.java, byXpath("//div[@class='FlatWelcomeFrame']"))
.size == 1
}
}

0 comments on commit e0c9234

Please sign in to comment.