Skip to content
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

Jetbrains | ASCA - UI test (AST-73515) #295

Merged
merged 10 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ group 'com.checkmarx'
version System.getenv('RELEASE_VERSION') ?: "dev"

def javaWrapperVersion = System.getenv('JAVA_WRAPPER_VERSION')
def remoteRobotVersion = '0.11.16'
def remoteRobotVersion = '0.11.23'

repositories {
mavenCentral()
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/checkmarx/intellij/ui/BaseUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.intellij.remoterobot.utils.RepeatUtilsKt;
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
import org.apache.commons.lang3.StringUtils;
import org.assertj.swing.fixture.JCheckBoxFixture;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -123,7 +122,7 @@ protected static void waitFor(Supplier<Boolean> condition) {
}
}

private static void openCxToolWindow() {
static void openCxToolWindow() {
log("Opening Cx Tool Window");
waitFor(() -> hasAnyComponent("//div[@tooltiptext.key='NOTIFICATION_GROUP_NAME']"));
if (!(hasAnyComponent(SETTINGS_ACTION) || hasAnyComponent(SETTINGS_BUTTON))) {
Expand Down
59 changes: 55 additions & 4 deletions src/test/java/com/checkmarx/intellij/ui/TestAsca.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package com.checkmarx.intellij.ui;

import com.automation.remarks.junit5.Video;
import com.intellij.remoterobot.fixtures.JTreeFixture;
import com.intellij.remoterobot.search.locators.Locators;
import com.intellij.remoterobot.fixtures.ComponentFixture;
import com.intellij.remoterobot.fixtures.dataExtractor.RemoteText;
import com.intellij.remoterobot.utils.Keyboard;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.awt.*;
import java.time.Duration;
import java.util.List;

import static com.checkmarx.intellij.ui.utils.RemoteRobotUtils.*;
import static com.checkmarx.intellij.ui.utils.Xpath.*;

public class TestAsca extends BaseUITest {

public void clickAscaCheckbox(){
public void clickAscaCheckbox() {
openSettings();
waitFor(() -> hasAnyComponent(ASCA_CHECKBOX));
click(ASCA_CHECKBOX);
waitFor(() -> hasAnyComponent(ASCA_INSTALL_SUCCESS));
Assertions.assertTrue(hasAnyComponent(ASCA_INSTALL_SUCCESS));
}

public void validateAscaRunning(){
public void validateAscaRunning() {
openSettings();
waitFor(() -> hasAnyComponent(ASCA_INSTALL_SUCCESS));
Assertions.assertTrue(hasAnyComponent(ASCA_INSTALL_SUCCESS));
Expand All @@ -41,4 +46,50 @@ public void clickAscaCheckbox_ExitSetting_OpenSetting_ValidateAscaRunning_Succes
validateAscaRunning();
click(OK_BTN);
}

@Test
@Video
public void AscaCheckboxEnabled_EnteringFileWithVulnerabilities_AscaVulnerabilityExist() {
// Attempt to find and click the project side tab button
ComponentFixture projectSideTabButton = find(ComponentFixture.class, "//div[contains(@tooltiptext.key, 'title.project')]", waitDuration);
try {
// We assume that project side tab is open, trying to click the project view tree
ComponentFixture projectViewTree = find(ComponentFixture.class, "//div[@class='JBViewport'][.//div[@class='ProjectViewTree']]", Duration.ofSeconds(1));
Point webGoatRootDirectoryPoint = projectViewTree.findAllText().get(0).getPoint();
projectViewTree.click(webGoatRootDirectoryPoint);
} catch (Exception e) {
// If the project side tab button is not open, click the project side tab button
projectSideTabButton.click();
}

// Navigate through the project directory to the specific file path
String[] path = {"webgoat-lessons", "challenge", "src", "main", "java", "challenge5", "Assignment5"};
for (String step : path) {
enter(step);
}

// Open the Problems view and search for a specific problem
click("//div[contains(@text.key, 'toolwindow.stripe.Problems_View')]");
click("//div[@class='BaseLabel' and @text='Problems:']");

ComponentFixture problems = find(ComponentFixture.class, "//div[@class='Tree']", waitDuration);

waitFor(() -> {
List<RemoteText> textList = problems.findAllText();
return textList.stream().anyMatch(t -> t.getText().contains("ASCA"));
});

Assertions.assertTrue(problems.findAllText().stream().anyMatch(t -> t.getText().contains("ASCA")));

openCxToolWindow();
}

protected static void enter(String value) {
Keyboard keyboard = new Keyboard(remoteRobot);
waitFor(() -> {
keyboard.enterText(value);
return hasAnyComponent(String.format(VISIBLE_TEXT, value));
});
keyboard.enter();
}
}
Loading