From 922f3a84cfcf0eb8090937fb3301ecd5066ef90b Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 3 Dec 2024 13:39:02 +0200 Subject: [PATCH 01/11] clean html description fix bug Eclipse display description incorrectly if vulnerability has "" --- .../checkmarx/eclipse/views/DataProvider.java | 100 ++++++++++++++---- 1 file changed, 81 insertions(+), 19 deletions(-) diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java index 13f4b3e..b238db5 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java @@ -366,33 +366,95 @@ private List addResults(String scanId, Map"); + } + /** * Creates a Display Model which represents each result - * - * @param resultItem - * @return + * + * @param resultItem Result object to transform + * @return DisplayModel representing the result */ private DisplayModel transform(Result resultItem) { - List nodes = Optional.ofNullable(resultItem.getData().getNodes()).orElse(Collections.emptyList()); - String queryName = resultItem.getData().getQueryName() != null ? resultItem.getData().getQueryName() : resultItem.getSimilarityId(); - String displayName = queryName; - if (nodes.size() > 0) { - Node node = nodes.get(0); - displayName += String.format(" (%s:%d)", new File(node.getFileName()).getName(), node.getLine()); - } - - return new DisplayModel.DisplayModelBuilder(displayName) - .setSeverity(resultItem.getSeverity()) - .setType(resultItem.getType()) - .setResult(resultItem) - .setSate(resultItem.getState()) - .setQueryName(queryName) - .build(); + List nodes = Optional.ofNullable(resultItem.getData().getNodes()).orElse(Collections.emptyList()); + + Result cleanResult = createCleanResult(resultItem); + + String queryName = cleanResult.getData().getQueryName() != null ? + cleanResult.getData().getQueryName() : + cleanResult.getSimilarityId(); + + String displayName = queryName; + if (nodes.size() > 0) { + Node node = nodes.get(0); + displayName += String.format(" (%s:%d)", new File(node.getFileName()).getName(), node.getLine()); + } + + return new DisplayModel.DisplayModelBuilder(displayName) + .setSeverity(cleanResult.getSeverity()) + .setType(cleanResult.getType()) + .setResult(cleanResult) + .setSate(cleanResult.getState()) + .setQueryName(queryName) + .build(); } /** * Group results by scanner type - * + * * @param allResultsTransformed * @return */ From c7f0cfc3b48b6263bb1a1920bc56d4b238d6856b Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 3 Dec 2024 17:12:27 +0200 Subject: [PATCH 02/11] Increase timeout --- .../java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index 34df1a2..4e132aa 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -60,7 +60,7 @@ public static void beforeClass() throws Exception { // Used to decrease tests velocity SWTBotPreferences.PLAYBACK_DELAY = 100; - SWTBotPreferences.TIMEOUT = 8000; + SWTBotPreferences.TIMEOUT = 15000; _bot = new SWTWorkbenchBot(); From dc533544cd81c1f4b2f4a924549c4937b1100199 Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 3 Dec 2024 17:32:58 +0200 Subject: [PATCH 03/11] check change for test --- .../eclipse/plugin/tests/ui/BaseUITest.java | 303 +++++++----------- 1 file changed, 108 insertions(+), 195 deletions(-) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index 4e132aa..c3f9c67 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -23,48 +23,37 @@ public abstract class BaseUITest { private static final String INFO_SUCCESSFUL_CONNECTION = "Successfully authenticated to Checkmarx One server!"; - - protected static final String ASSERT_FILTER_ACTIONS_IN_TOOLBAR = "All filter actions must be in the tool bar"; - + protected static final String ASSERT_FILTER_ACTIONS_IN_TOOLBAR = "All filter actions must be in the toolbar"; protected static final String TAB_WINDOW = "Window"; - protected static final String ITEM_SHOW_VIEW = "Show View"; protected static final String ITEM_PREFERENCES = "Preferences"; protected static final String ITEM_OTHER = "Other..."; protected static final String ITEM_CHECKMARX = "Checkmarx"; protected static final String ITEM_CHECKMARX_AST = "Checkmarx One"; protected static final String ITEM_CHECKMARX_AST_SCAN = "Checkmarx One Scan"; - - protected static final String LABEL_SCAN_ID = "Scan Id:"; - + protected static final String BTN_OPEN = "Open"; protected static final String BTN_APPLY = "Apply"; protected static final String BTN_TEST_CONNECTION = "Test Connection"; - protected static final String BTN_OK = "OK"; protected static final String BTN_APPLY_AND_CLOSE = "Apply and Close"; - - protected static final String SHELL_AUTHENTICATION = "Authentication"; - + protected static final String VIEW_CHECKMARX_AST_SCAN = "Checkmarx One Scan"; - + protected static SWTWorkbenchBot _bot; private static boolean eclipseProjectExist = false; - + protected static boolean _cxSettingsDefined = false; - + @BeforeClass public static void beforeClass() throws Exception { - // Needed to set CI environment keyboard layout - SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; - - // Used to decrease tests velocity + // Set preferences for the test environment + SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; SWTBotPreferences.PLAYBACK_DELAY = 100; - - SWTBotPreferences.TIMEOUT = 15000; + SWTBotPreferences.TIMEOUT = 20000; // Timeout increased to 20 seconds _bot = new SWTWorkbenchBot(); - - if(!eclipseProjectExist) { + + if (!eclipseProjectExist) { createEclipseProject(); eclipseProjectExist = true; } @@ -72,20 +61,20 @@ public static void beforeClass() throws Exception { @After public void tearDown() throws Exception { + // Optional cleanup logic if required } - + @AfterClass - public static void sleep() { - _bot.sleep(2000); + public static void afterClass() { + _bot.sleep(2000); // Stabilize teardown } - - + protected static void sleep(long millis) { _bot.sleep(millis); } - + /** - * Used to get the workbench focus back and avoid "widget was null" error message in the CI environment + * Ensures workbench is focused to avoid null widget errors in CI. */ protected static void preventWidgetWasNullInCIEnvironment() { UIThreadRunnable.syncExec(new VoidResult() { @@ -94,225 +83,149 @@ public void run() { } }); } - + /** - * Set up checkmarx plugin - * - * -> Set credentials - * -> Test connection - * -> Add checkmarx plugin - * - * @throws TimeoutException + * Waits until the Branch ComboBox is enabled. */ - protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws TimeoutException { - // Test Connection - testSuccessfulConnection(false); - - // Add Checkmarx One Plugin - addCheckmarxPlugin(true); - + protected static void waitUntilBranchComboIsEnabled() throws TimeoutException { preventWidgetWasNullInCIEnvironment(); - - if(!ignoreWrongScanValidation) { - // Test incorrect Scan ID format - _bot.comboBox(2).setText("invalid-scan-id"); - _bot.comboBox(2).pressShortcut(Keystrokes.LF); - sleep(1000); + int retryIdx = 0; - assertEquals("The tree must contain one row with an error message", _bot.tree(1).rowCount(), 1); - assertEquals("An incorrect scanId format message must be displayed", PluginConstants.TREE_INVALID_SCAN_ID_FORMAT, _bot.tree(1).cell(0, 0)); + while (!_bot.comboBox(1).isEnabled()) { + System.out.println("Retry #" + retryIdx + ": ComboBox is not enabled yet."); + if (retryIdx++ >= 10) { + throw new TimeoutException("Branch ComboBox not enabled within 20000ms. Check environment or plugin state."); + } + _bot.sleep(2000); // Adjusted sleep duration } - - // clear the view before getting the scan id - _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(PluginConstants.TOOLBAR_ACTION_CLEAR_RESULTS).click(); - - sleep(1000); - - // type a valid and existing Scan ID - typeValidScanID(); - - assertEquals("The tree must contain one row", _bot.tree().rowCount(), 1); - boolean retrievingOrRetrievedResults = _bot.tree(1).cell(0, 0).contains(Environment.SCAN_ID); - assertTrue("The plugin should have or should be retrieving results", retrievingOrRetrievedResults); - waitWhileTreeNodeEqualsTo(String.format(PluginConstants.RETRIEVING_RESULTS_FOR_SCAN, Environment.SCAN_ID)); - - assertTrue("The plugin should retrieve results", _bot.tree(1).cell(0, 0).startsWith(Environment.SCAN_ID)); + System.out.println("Branch ComboBox is enabled."); } /** - * Test successful connection - * - * @throws TimeoutException + * Waits for a successful connection response from the Checkmarx server. */ - protected void testSuccessfulConnection(boolean openFromInitialPanel) throws TimeoutException { - preventWidgetWasNullInCIEnvironment(); - - if(_cxSettingsDefined) return; - - if(!openFromInitialPanel) { - _bot.menu(TAB_WINDOW).menu(ITEM_PREFERENCES).click(); - _bot.shell(ITEM_PREFERENCES).activate(); - _bot.tree().select(ITEM_CHECKMARX_AST); - } - - _bot.sleep(1000); - - _bot.shell(ITEM_PREFERENCES).setFocus(); // Need to set focus to avoid failing in CI environment - - _bot.textWithLabel(PluginConstants.PREFERENCES_API_KEY).setText(Environment.API_KEY); + protected static void waitForConnectionResponse() throws TimeoutException { + int retryIdx = 0; - _bot.button(BTN_APPLY).click(); - _bot.button(BTN_TEST_CONNECTION).click(); - - //Do waitUntil Method to get text from text(6) - waitForConnectionResponse(); - - _bot.shell(ITEM_PREFERENCES).setFocus(); // Need to set focus to avoid failing in CI environment - _bot.button(BTN_APPLY_AND_CLOSE).click(); + while (!_bot.text(3).getText().equals(INFO_SUCCESSFUL_CONNECTION)) { + System.out.println("Retry #" + retryIdx + ": Waiting for successful connection..."); + if (retryIdx++ >= 10) { + throw new TimeoutException("Connection validation timeout after 20000ms."); + } + _bot.sleep(2000); // Adjusted sleep for better debugging + } - _cxSettingsDefined = true; + System.out.println("Connection successful!"); } - /** - * Add Checkmarx plugin in the show view perspective - * - * @throws TimeoutException - */ - protected void addCheckmarxPlugin(boolean waitUntilPluginEnable) throws TimeoutException { - preventWidgetWasNullInCIEnvironment(); - - _bot.menu(TAB_WINDOW).menu(ITEM_SHOW_VIEW).menu(ITEM_OTHER).click(); - _bot.shell(ITEM_SHOW_VIEW).activate(); - _bot.tree().expandNode(ITEM_CHECKMARX).select(ITEM_CHECKMARX_AST_SCAN); - _bot.button(BTN_OPEN).click(); - - if(waitUntilPluginEnable) { - waitUntilBranchComboIsEnabled(); - } - } - - /** - * Wait while tree node equals to a a specific message. Fails after 10 retries - * - * @param nodeText - * @throws TimeoutException + * Waits while tree node equals a specific message. Fails after 10 retries. */ protected static void waitWhileTreeNodeEqualsTo(String nodeText) throws TimeoutException { int retryIdx = 0; while (_bot.tree().getAllItems()[0].getText().equals(nodeText)) { - - if (retryIdx == 10) { - break; + System.out.println("Retry #" + retryIdx + ": Tree node still equals to '" + nodeText + "'."); + if (retryIdx++ >= 10) { + throw new TimeoutException("Timeout after 20000ms. Expected tree node to change, but it didn't."); } + _bot.sleep(2000); + } - _bot.sleep(1000); + System.out.println("Tree node updated successfully."); + } - retryIdx++; - } + /** + * Sets up the Checkmarx plugin: sets credentials, tests connection, and adds the plugin. + */ + protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws TimeoutException { + testSuccessfulConnection(false); + addCheckmarxPlugin(true); - if (retryIdx == 10) { - throw new TimeoutException("Timeout after 5000ms. Scan results should be retrieved"); + if (!ignoreWrongScanValidation) { + validateInvalidScanID(); } + + clearResultsView(); + typeValidScanID(); + + assertTreeContainsScanID(); } - + /** - * Wait until branch combobox is enabled - * - * @throws TimeoutException + * Validates connection with Checkmarx credentials. */ - protected static void waitUntilBranchComboIsEnabled() throws TimeoutException { - preventWidgetWasNullInCIEnvironment(); - - boolean emptyScanId = _bot.comboBox(2).getText().isEmpty() || _bot.comboBox(2).getText().equals(PluginConstants.COMBOBOX_SCAND_ID_PLACEHOLDER); - boolean projectNotSelected =_bot.comboBox(0).getText().isEmpty() || _bot.comboBox(0).getText().equals("Select a project"); - - if(emptyScanId || projectNotSelected) { - return; + protected void testSuccessfulConnection(boolean openFromInitialPanel) throws TimeoutException { + if (_cxSettingsDefined) return; + + if (!openFromInitialPanel) { + openPreferences(); } - - int retryIdx = 0; - while (!_bot.comboBox(1).isEnabled()) { + configureCredentials(); + waitForConnectionResponse(); - if (retryIdx == 10) { - break; - } + closePreferences(); + _cxSettingsDefined = true; + } - _bot.sleep(8000); + private void openPreferences() { + _bot.menu(TAB_WINDOW).menu(ITEM_PREFERENCES).click(); + _bot.shell(ITEM_PREFERENCES).activate(); + _bot.tree().select(ITEM_CHECKMARX_AST); + } - retryIdx++; - } + private void configureCredentials() { + _bot.textWithLabel(PluginConstants.PREFERENCES_API_KEY).setText(Environment.API_KEY); + _bot.button(BTN_APPLY).click(); + _bot.button(BTN_TEST_CONNECTION).click(); + } - if (retryIdx == 10) { - emptyScanId = _bot.comboBox(2).getText().isEmpty() || _bot.comboBox(2).getText().equals(PluginConstants.COMBOBOX_SCAND_ID_PLACEHOLDER); - projectNotSelected = _bot.comboBox(0).getText().isEmpty() || _bot.comboBox(0).getText().equals("Select a project"); - - if(emptyScanId || projectNotSelected) { - return; - } - - throw new TimeoutException("Timeout after 5000ms. Branches' combobox must be enabled"); - } + private void closePreferences() { + _bot.shell(ITEM_PREFERENCES).setFocus(); + _bot.button(BTN_APPLY_AND_CLOSE).click(); } - - /** - * Wait while tree node equals to a a specific message. Fails after 10 retries - * - * @param nodeText - * @throws TimeoutException - */ - protected static void waitForConnectionResponse() throws TimeoutException { - int retryIdx = 0; - while (!_bot.text(3).getText().equals(INFO_SUCCESSFUL_CONNECTION)) { - if (retryIdx == 10) { - break; - } - _bot.sleep(1000); - retryIdx++; - } + private void validateInvalidScanID() { + _bot.comboBox(2).setText("invalid-scan-id"); + _bot.comboBox(2).pressShortcut(Keystrokes.LF); - if (retryIdx == 10) { - throw new TimeoutException("Connection validation timeout after 10000ms."); - } + sleep(1000); + assertEquals("The tree must contain one row with an error message", 1, _bot.tree(1).rowCount()); + assertEquals("Invalid Scan ID format message must be displayed", + PluginConstants.TREE_INVALID_SCAN_ID_FORMAT, _bot.tree(1).cell(0, 0)); + } + + private void clearResultsView() { + _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(PluginConstants.TOOLBAR_ACTION_CLEAR_RESULTS).click(); + sleep(1000); } - - /** - * Type a valid Scan ID to get results - * - * @throws TimeoutException - */ private void typeValidScanID() throws TimeoutException { preventWidgetWasNullInCIEnvironment(); - + _bot.comboBox(2).setText(Environment.SCAN_ID); _bot.comboBox(2).pressShortcut(Keystrokes.LF); - + waitUntilBranchComboIsEnabled(); } - - /** - * Create a eclipse project - */ + + private void assertTreeContainsScanID() { + assertEquals("The tree must contain one row", 1, _bot.tree(1).rowCount()); + assertTrue("The plugin should have or should be retrieving results", + _bot.tree(1).cell(0, 0).contains(Environment.SCAN_ID)); + } + private static void createEclipseProject() { _bot.menu("File").menu("New").menu("Project...").click(); SWTBotShell shell = _bot.shell("New Project"); shell.activate(); _bot.tree().select("Project"); _bot.button("Next >").click(); - - + _bot.textWithLabel("Project name:").setText("MyFirstProject"); _bot.button("Finish").click(); - - _bot.menu("File").menu("New").menu("File").click(); - _bot.textWithLabel("File name:").setText("Dockerfile"); - _bot.tree().select(0); - _bot.button("Finish").click(); } } From 69552818ed94986cb6a19a22862a285541840eaf Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 3 Dec 2024 17:37:34 +0200 Subject: [PATCH 04/11] revert --- .../eclipse/plugin/tests/ui/BaseUITest.java | 263 ++++++++++++------ 1 file changed, 175 insertions(+), 88 deletions(-) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index c3f9c67..0bf07e4 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -23,8 +23,11 @@ public abstract class BaseUITest { private static final String INFO_SUCCESSFUL_CONNECTION = "Successfully authenticated to Checkmarx One server!"; - protected static final String ASSERT_FILTER_ACTIONS_IN_TOOLBAR = "All filter actions must be in the toolbar"; + + protected static final String ASSERT_FILTER_ACTIONS_IN_TOOLBAR = "All filter actions must be in the tool bar"; + protected static final String TAB_WINDOW = "Window"; + protected static final String ITEM_SHOW_VIEW = "Show View"; protected static final String ITEM_PREFERENCES = "Preferences"; protected static final String ITEM_OTHER = "Other..."; @@ -32,11 +35,16 @@ public abstract class BaseUITest { protected static final String ITEM_CHECKMARX_AST = "Checkmarx One"; protected static final String ITEM_CHECKMARX_AST_SCAN = "Checkmarx One Scan"; + protected static final String LABEL_SCAN_ID = "Scan Id:"; + protected static final String BTN_OPEN = "Open"; protected static final String BTN_APPLY = "Apply"; protected static final String BTN_TEST_CONNECTION = "Test Connection"; + protected static final String BTN_OK = "OK"; protected static final String BTN_APPLY_AND_CLOSE = "Apply and Close"; + protected static final String SHELL_AUTHENTICATION = "Authentication"; + protected static final String VIEW_CHECKMARX_AST_SCAN = "Checkmarx One Scan"; protected static SWTWorkbenchBot _bot; @@ -46,14 +54,17 @@ public abstract class BaseUITest { @BeforeClass public static void beforeClass() throws Exception { - // Set preferences for the test environment + // Needed to set CI environment keyboard layout SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; + + // Used to decrease tests velocity SWTBotPreferences.PLAYBACK_DELAY = 100; - SWTBotPreferences.TIMEOUT = 20000; // Timeout increased to 20 seconds + + SWTBotPreferences.TIMEOUT = 8000; _bot = new SWTWorkbenchBot(); - if (!eclipseProjectExist) { + if(!eclipseProjectExist) { createEclipseProject(); eclipseProjectExist = true; } @@ -61,20 +72,20 @@ public static void beforeClass() throws Exception { @After public void tearDown() throws Exception { - // Optional cleanup logic if required } @AfterClass - public static void afterClass() { - _bot.sleep(2000); // Stabilize teardown + public static void sleep() { + _bot.sleep(2000); } + protected static void sleep(long millis) { _bot.sleep(millis); } /** - * Ensures workbench is focused to avoid null widget errors in CI. + * Used to get the workbench focus back and avoid "widget was null" error message in the CI environment */ protected static void preventWidgetWasNullInCIEnvironment() { UIThreadRunnable.syncExec(new VoidResult() { @@ -85,124 +96,197 @@ public void run() { } /** - * Waits until the Branch ComboBox is enabled. + * Set up checkmarx plugin + * + * -> Set credentials + * -> Test connection + * -> Add checkmarx plugin + * + * @throws TimeoutException */ - protected static void waitUntilBranchComboIsEnabled() throws TimeoutException { + protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws TimeoutException { + // Test Connection + testSuccessfulConnection(false); + + // Add Checkmarx One Plugin + addCheckmarxPlugin(true); + preventWidgetWasNullInCIEnvironment(); - int retryIdx = 0; + if(!ignoreWrongScanValidation) { + // Test incorrect Scan ID format + _bot.comboBox(2).setText("invalid-scan-id"); + _bot.comboBox(2).pressShortcut(Keystrokes.LF); - while (!_bot.comboBox(1).isEnabled()) { - System.out.println("Retry #" + retryIdx + ": ComboBox is not enabled yet."); - if (retryIdx++ >= 10) { - throw new TimeoutException("Branch ComboBox not enabled within 20000ms. Check environment or plugin state."); - } - _bot.sleep(2000); // Adjusted sleep duration + sleep(1000); + + assertEquals("The tree must contain one row with an error message", _bot.tree(1).rowCount(), 1); + assertEquals("An incorrect scanId format message must be displayed", PluginConstants.TREE_INVALID_SCAN_ID_FORMAT, _bot.tree(1).cell(0, 0)); } - System.out.println("Branch ComboBox is enabled."); + // clear the view before getting the scan id + _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(PluginConstants.TOOLBAR_ACTION_CLEAR_RESULTS).click(); + + sleep(1000); + + // type a valid and existing Scan ID + typeValidScanID(); + + assertEquals("The tree must contain one row", _bot.tree().rowCount(), 1); + boolean retrievingOrRetrievedResults = _bot.tree(1).cell(0, 0).contains(Environment.SCAN_ID); + assertTrue("The plugin should have or should be retrieving results", retrievingOrRetrievedResults); + + waitWhileTreeNodeEqualsTo(String.format(PluginConstants.RETRIEVING_RESULTS_FOR_SCAN, Environment.SCAN_ID)); + + assertTrue("The plugin should retrieve results", _bot.tree(1).cell(0, 0).startsWith(Environment.SCAN_ID)); } /** - * Waits for a successful connection response from the Checkmarx server. + * Test successful connection + * + * @throws TimeoutException */ - protected static void waitForConnectionResponse() throws TimeoutException { - int retryIdx = 0; + protected void testSuccessfulConnection(boolean openFromInitialPanel) throws TimeoutException { + preventWidgetWasNullInCIEnvironment(); - while (!_bot.text(3).getText().equals(INFO_SUCCESSFUL_CONNECTION)) { - System.out.println("Retry #" + retryIdx + ": Waiting for successful connection..."); - if (retryIdx++ >= 10) { - throw new TimeoutException("Connection validation timeout after 20000ms."); - } - _bot.sleep(2000); // Adjusted sleep for better debugging + if(_cxSettingsDefined) return; + + if(!openFromInitialPanel) { + _bot.menu(TAB_WINDOW).menu(ITEM_PREFERENCES).click(); + _bot.shell(ITEM_PREFERENCES).activate(); + _bot.tree().select(ITEM_CHECKMARX_AST); } - System.out.println("Connection successful!"); + _bot.sleep(1000); + + _bot.shell(ITEM_PREFERENCES).setFocus(); // Need to set focus to avoid failing in CI environment + + _bot.textWithLabel(PluginConstants.PREFERENCES_API_KEY).setText(Environment.API_KEY); + + _bot.button(BTN_APPLY).click(); + _bot.button(BTN_TEST_CONNECTION).click(); + + //Do waitUntil Method to get text from text(6) + waitForConnectionResponse(); + + _bot.shell(ITEM_PREFERENCES).setFocus(); // Need to set focus to avoid failing in CI environment + _bot.button(BTN_APPLY_AND_CLOSE).click(); + + _cxSettingsDefined = true; + } + + + /** + * Add Checkmarx plugin in the show view perspective + * + * @throws TimeoutException + */ + protected void addCheckmarxPlugin(boolean waitUntilPluginEnable) throws TimeoutException { + preventWidgetWasNullInCIEnvironment(); + + _bot.menu(TAB_WINDOW).menu(ITEM_SHOW_VIEW).menu(ITEM_OTHER).click(); + _bot.shell(ITEM_SHOW_VIEW).activate(); + _bot.tree().expandNode(ITEM_CHECKMARX).select(ITEM_CHECKMARX_AST_SCAN); + _bot.button(BTN_OPEN).click(); + + if(waitUntilPluginEnable) { + waitUntilBranchComboIsEnabled(); + } } /** - * Waits while tree node equals a specific message. Fails after 10 retries. + * Wait while tree node equals to a a specific message. Fails after 10 retries + * + * @param nodeText + * @throws TimeoutException */ protected static void waitWhileTreeNodeEqualsTo(String nodeText) throws TimeoutException { int retryIdx = 0; while (_bot.tree().getAllItems()[0].getText().equals(nodeText)) { - System.out.println("Retry #" + retryIdx + ": Tree node still equals to '" + nodeText + "'."); - if (retryIdx++ >= 10) { - throw new TimeoutException("Timeout after 20000ms. Expected tree node to change, but it didn't."); + + if (retryIdx == 10) { + break; } - _bot.sleep(2000); + + _bot.sleep(1000); + + retryIdx++; } - System.out.println("Tree node updated successfully."); + if (retryIdx == 10) { + throw new TimeoutException("Timeout after 5000ms. Scan results should be retrieved"); + } } /** - * Sets up the Checkmarx plugin: sets credentials, tests connection, and adds the plugin. + * Wait until branch combobox is enabled + * + * @throws TimeoutException */ - protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws TimeoutException { - testSuccessfulConnection(false); - addCheckmarxPlugin(true); + protected static void waitUntilBranchComboIsEnabled() throws TimeoutException { + preventWidgetWasNullInCIEnvironment(); - if (!ignoreWrongScanValidation) { - validateInvalidScanID(); + boolean emptyScanId = _bot.comboBox(2).getText().isEmpty() || _bot.comboBox(2).getText().equals(PluginConstants.COMBOBOX_SCAND_ID_PLACEHOLDER); + boolean projectNotSelected =_bot.comboBox(0).getText().isEmpty() || _bot.comboBox(0).getText().equals("Select a project"); + + if(emptyScanId || projectNotSelected) { + return; } - clearResultsView(); - typeValidScanID(); + int retryIdx = 0; - assertTreeContainsScanID(); - } + while (!_bot.comboBox(1).isEnabled()) { - /** - * Validates connection with Checkmarx credentials. - */ - protected void testSuccessfulConnection(boolean openFromInitialPanel) throws TimeoutException { - if (_cxSettingsDefined) return; + if (retryIdx == 10) { + break; + } - if (!openFromInitialPanel) { - openPreferences(); + _bot.sleep(8000); + + retryIdx++; } - configureCredentials(); - waitForConnectionResponse(); + if (retryIdx == 10) { + emptyScanId = _bot.comboBox(2).getText().isEmpty() || _bot.comboBox(2).getText().equals(PluginConstants.COMBOBOX_SCAND_ID_PLACEHOLDER); + projectNotSelected = _bot.comboBox(0).getText().isEmpty() || _bot.comboBox(0).getText().equals("Select a project"); - closePreferences(); - _cxSettingsDefined = true; - } - - private void openPreferences() { - _bot.menu(TAB_WINDOW).menu(ITEM_PREFERENCES).click(); - _bot.shell(ITEM_PREFERENCES).activate(); - _bot.tree().select(ITEM_CHECKMARX_AST); - } + if(emptyScanId || projectNotSelected) { + return; + } - private void configureCredentials() { - _bot.textWithLabel(PluginConstants.PREFERENCES_API_KEY).setText(Environment.API_KEY); - _bot.button(BTN_APPLY).click(); - _bot.button(BTN_TEST_CONNECTION).click(); + throw new TimeoutException("Timeout after 5000ms. Branches' combobox must be enabled"); + } } - private void closePreferences() { - _bot.shell(ITEM_PREFERENCES).setFocus(); - _bot.button(BTN_APPLY_AND_CLOSE).click(); - } + /** + * Wait while tree node equals to a a specific message. Fails after 10 retries + * + * @param nodeText + * @throws TimeoutException + */ + protected static void waitForConnectionResponse() throws TimeoutException { + int retryIdx = 0; + while (!_bot.text(3).getText().equals(INFO_SUCCESSFUL_CONNECTION)) { + if (retryIdx == 10) { + break; + } - private void validateInvalidScanID() { - _bot.comboBox(2).setText("invalid-scan-id"); - _bot.comboBox(2).pressShortcut(Keystrokes.LF); + _bot.sleep(1000); + retryIdx++; + } - sleep(1000); - assertEquals("The tree must contain one row with an error message", 1, _bot.tree(1).rowCount()); - assertEquals("Invalid Scan ID format message must be displayed", - PluginConstants.TREE_INVALID_SCAN_ID_FORMAT, _bot.tree(1).cell(0, 0)); + if (retryIdx == 10) { + throw new TimeoutException("Connection validation timeout after 10000ms."); + } } - private void clearResultsView() { - _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(PluginConstants.TOOLBAR_ACTION_CLEAR_RESULTS).click(); - sleep(1000); - } + /** + * Type a valid Scan ID to get results + * + * @throws TimeoutException + */ private void typeValidScanID() throws TimeoutException { preventWidgetWasNullInCIEnvironment(); @@ -212,12 +296,9 @@ private void typeValidScanID() throws TimeoutException { waitUntilBranchComboIsEnabled(); } - private void assertTreeContainsScanID() { - assertEquals("The tree must contain one row", 1, _bot.tree(1).rowCount()); - assertTrue("The plugin should have or should be retrieving results", - _bot.tree(1).cell(0, 0).contains(Environment.SCAN_ID)); - } - + /** + * Create a eclipse project + */ private static void createEclipseProject() { _bot.menu("File").menu("New").menu("Project...").click(); SWTBotShell shell = _bot.shell("New Project"); @@ -225,7 +306,13 @@ private static void createEclipseProject() { _bot.tree().select("Project"); _bot.button("Next >").click(); + _bot.textWithLabel("Project name:").setText("MyFirstProject"); _bot.button("Finish").click(); + + _bot.menu("File").menu("New").menu("File").click(); + _bot.textWithLabel("File name:").setText("Dockerfile"); + _bot.tree().select(0); + _bot.button("Finish").click(); } -} +} \ No newline at end of file From 28dc4b02364bf34d880df74851313ad4b04ab972 Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 3 Dec 2024 17:59:50 +0200 Subject: [PATCH 05/11] change to CX_TEST_SCAN from SCAN_ID --- .../ast/eclipse/plugin/tests/ui/BaseUITest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index 0bf07e4..10c8b97 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -35,7 +35,7 @@ public abstract class BaseUITest { protected static final String ITEM_CHECKMARX_AST = "Checkmarx One"; protected static final String ITEM_CHECKMARX_AST_SCAN = "Checkmarx One Scan"; - protected static final String LABEL_SCAN_ID = "Scan Id:"; + protected static final String LABEL_CX_TEST_SCAN = "Scan Id:"; protected static final String BTN_OPEN = "Open"; protected static final String BTN_APPLY = "Apply"; @@ -121,7 +121,7 @@ protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws Ti sleep(1000); assertEquals("The tree must contain one row with an error message", _bot.tree(1).rowCount(), 1); - assertEquals("An incorrect scanId format message must be displayed", PluginConstants.TREE_INVALID_SCAN_ID_FORMAT, _bot.tree(1).cell(0, 0)); + assertEquals("An incorrect scanId format message must be displayed", PluginConstants.TREE_INVALID_CX_TEST_SCAN_FORMAT, _bot.tree(1).cell(0, 0)); } // clear the view before getting the scan id @@ -133,12 +133,12 @@ protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws Ti typeValidScanID(); assertEquals("The tree must contain one row", _bot.tree().rowCount(), 1); - boolean retrievingOrRetrievedResults = _bot.tree(1).cell(0, 0).contains(Environment.SCAN_ID); + boolean retrievingOrRetrievedResults = _bot.tree(1).cell(0, 0).contains(Environment.CX_TEST_SCAN); assertTrue("The plugin should have or should be retrieving results", retrievingOrRetrievedResults); - waitWhileTreeNodeEqualsTo(String.format(PluginConstants.RETRIEVING_RESULTS_FOR_SCAN, Environment.SCAN_ID)); + waitWhileTreeNodeEqualsTo(String.format(PluginConstants.RETRIEVING_RESULTS_FOR_SCAN, Environment.CX_TEST_SCAN)); - assertTrue("The plugin should retrieve results", _bot.tree(1).cell(0, 0).startsWith(Environment.SCAN_ID)); + assertTrue("The plugin should retrieve results", _bot.tree(1).cell(0, 0).startsWith(Environment.CX_TEST_SCAN)); } /** @@ -290,7 +290,7 @@ protected static void waitForConnectionResponse() throws TimeoutException { private void typeValidScanID() throws TimeoutException { preventWidgetWasNullInCIEnvironment(); - _bot.comboBox(2).setText(Environment.SCAN_ID); + _bot.comboBox(2).setText(Environment.CX_TEST_SCAN); _bot.comboBox(2).pressShortcut(Keystrokes.LF); waitUntilBranchComboIsEnabled(); From 29775e7a9525dee24d6d44d0661e36cffb1799cf Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 3 Dec 2024 18:15:06 +0200 Subject: [PATCH 06/11] Update BaseUITest.java --- .../ast/eclipse/plugin/tests/ui/BaseUITest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index 10c8b97..22c1667 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -290,6 +290,16 @@ protected static void waitForConnectionResponse() throws TimeoutException { private void typeValidScanID() throws TimeoutException { preventWidgetWasNullInCIEnvironment(); + String scanId = System.getenv("SCAN_ID"); + String scanId2 = System.getenv("CX_TEST_SCAN"); + String scanId3 = Environment.SCAN_ID; + + if (scanId == null || scanId2 == null || scanId3 == null) { + throw new IllegalArgumentException("Environment variable Environment.SCAN_ID is not set. Value: " + scanId + + "Environment variable SCAN_ID2 is not set. Value: " + scanId2 + "Environment variable SCAN_ID3 is not set. Value: " + scanId3); + } + + _bot.comboBox(2).setText(Environment.CX_TEST_SCAN); _bot.comboBox(2).pressShortcut(Keystrokes.LF); From 94221a43f8a459ae51aed0094060775ea6169c52 Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 3 Dec 2024 18:23:37 +0200 Subject: [PATCH 07/11] Update BaseUITest.java --- .../ast/eclipse/plugin/tests/ui/BaseUITest.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index 22c1667..ec41dea 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -133,12 +133,12 @@ protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws Ti typeValidScanID(); assertEquals("The tree must contain one row", _bot.tree().rowCount(), 1); - boolean retrievingOrRetrievedResults = _bot.tree(1).cell(0, 0).contains(Environment.CX_TEST_SCAN); + boolean retrievingOrRetrievedResults = _bot.tree(1).cell(0, 0).contains(Environment.SCAN_ID); assertTrue("The plugin should have or should be retrieving results", retrievingOrRetrievedResults); - waitWhileTreeNodeEqualsTo(String.format(PluginConstants.RETRIEVING_RESULTS_FOR_SCAN, Environment.CX_TEST_SCAN)); + waitWhileTreeNodeEqualsTo(String.format(PluginConstants.RETRIEVING_RESULTS_FOR_SCAN, Environment.SCAN_ID)); - assertTrue("The plugin should retrieve results", _bot.tree(1).cell(0, 0).startsWith(Environment.CX_TEST_SCAN)); + assertTrue("The plugin should retrieve results", _bot.tree(1).cell(0, 0).startsWith(Environment.SCAN_ID)); } /** @@ -299,8 +299,7 @@ private void typeValidScanID() throws TimeoutException { + "Environment variable SCAN_ID2 is not set. Value: " + scanId2 + "Environment variable SCAN_ID3 is not set. Value: " + scanId3); } - - _bot.comboBox(2).setText(Environment.CX_TEST_SCAN); + _bot.comboBox(2).setText(Environment.SCAN_ID); _bot.comboBox(2).pressShortcut(Keystrokes.LF); waitUntilBranchComboIsEnabled(); From 730826a0e9248858590288ecf0f6664c50376331 Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 3 Dec 2024 18:27:37 +0200 Subject: [PATCH 08/11] Update BaseUITest.java --- .../java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index ec41dea..12abe57 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -121,7 +121,7 @@ protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws Ti sleep(1000); assertEquals("The tree must contain one row with an error message", _bot.tree(1).rowCount(), 1); - assertEquals("An incorrect scanId format message must be displayed", PluginConstants.TREE_INVALID_CX_TEST_SCAN_FORMAT, _bot.tree(1).cell(0, 0)); + assertEquals("An incorrect scanId format message must be displayed", PluginConstants.TREE_INVALID_SCAN_ID_FORMAT, _bot.tree(1).cell(0, 0)); } // clear the view before getting the scan id From bf7d9c828e1053ecf36639be64b21d4c41c93615 Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 3 Dec 2024 18:50:07 +0200 Subject: [PATCH 09/11] revert --- .../eclipse/plugin/tests/ui/BaseUITest.java | 133 ++++++++---------- 1 file changed, 62 insertions(+), 71 deletions(-) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index 12abe57..4e132aa 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -23,47 +23,47 @@ public abstract class BaseUITest { private static final String INFO_SUCCESSFUL_CONNECTION = "Successfully authenticated to Checkmarx One server!"; - + protected static final String ASSERT_FILTER_ACTIONS_IN_TOOLBAR = "All filter actions must be in the tool bar"; - + protected static final String TAB_WINDOW = "Window"; - + protected static final String ITEM_SHOW_VIEW = "Show View"; protected static final String ITEM_PREFERENCES = "Preferences"; protected static final String ITEM_OTHER = "Other..."; protected static final String ITEM_CHECKMARX = "Checkmarx"; protected static final String ITEM_CHECKMARX_AST = "Checkmarx One"; protected static final String ITEM_CHECKMARX_AST_SCAN = "Checkmarx One Scan"; - - protected static final String LABEL_CX_TEST_SCAN = "Scan Id:"; - + + protected static final String LABEL_SCAN_ID = "Scan Id:"; + protected static final String BTN_OPEN = "Open"; protected static final String BTN_APPLY = "Apply"; protected static final String BTN_TEST_CONNECTION = "Test Connection"; protected static final String BTN_OK = "OK"; protected static final String BTN_APPLY_AND_CLOSE = "Apply and Close"; - + protected static final String SHELL_AUTHENTICATION = "Authentication"; - + protected static final String VIEW_CHECKMARX_AST_SCAN = "Checkmarx One Scan"; - + protected static SWTWorkbenchBot _bot; private static boolean eclipseProjectExist = false; - + protected static boolean _cxSettingsDefined = false; - + @BeforeClass public static void beforeClass() throws Exception { // Needed to set CI environment keyboard layout - SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; + SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; // Used to decrease tests velocity SWTBotPreferences.PLAYBACK_DELAY = 100; - - SWTBotPreferences.TIMEOUT = 8000; + + SWTBotPreferences.TIMEOUT = 15000; _bot = new SWTWorkbenchBot(); - + if(!eclipseProjectExist) { createEclipseProject(); eclipseProjectExist = true; @@ -73,17 +73,17 @@ public static void beforeClass() throws Exception { @After public void tearDown() throws Exception { } - + @AfterClass public static void sleep() { _bot.sleep(2000); } - - + + protected static void sleep(long millis) { _bot.sleep(millis); } - + /** * Used to get the workbench focus back and avoid "widget was null" error message in the CI environment */ @@ -94,14 +94,14 @@ public void run() { } }); } - + /** * Set up checkmarx plugin - * + * * -> Set credentials * -> Test connection * -> Add checkmarx plugin - * + * * @throws TimeoutException */ protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws TimeoutException { @@ -110,9 +110,9 @@ protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws Ti // Add Checkmarx One Plugin addCheckmarxPlugin(true); - + preventWidgetWasNullInCIEnvironment(); - + if(!ignoreWrongScanValidation) { // Test incorrect Scan ID format _bot.comboBox(2).setText("invalid-scan-id"); @@ -123,34 +123,34 @@ protected void setUpCheckmarxPlugin(boolean ignoreWrongScanValidation) throws Ti assertEquals("The tree must contain one row with an error message", _bot.tree(1).rowCount(), 1); assertEquals("An incorrect scanId format message must be displayed", PluginConstants.TREE_INVALID_SCAN_ID_FORMAT, _bot.tree(1).cell(0, 0)); } - + // clear the view before getting the scan id _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(PluginConstants.TOOLBAR_ACTION_CLEAR_RESULTS).click(); - + sleep(1000); - + // type a valid and existing Scan ID typeValidScanID(); - assertEquals("The tree must contain one row", _bot.tree().rowCount(), 1); + assertEquals("The tree must contain one row", _bot.tree().rowCount(), 1); boolean retrievingOrRetrievedResults = _bot.tree(1).cell(0, 0).contains(Environment.SCAN_ID); assertTrue("The plugin should have or should be retrieving results", retrievingOrRetrievedResults); waitWhileTreeNodeEqualsTo(String.format(PluginConstants.RETRIEVING_RESULTS_FOR_SCAN, Environment.SCAN_ID)); - + assertTrue("The plugin should retrieve results", _bot.tree(1).cell(0, 0).startsWith(Environment.SCAN_ID)); } /** * Test successful connection - * + * * @throws TimeoutException */ protected void testSuccessfulConnection(boolean openFromInitialPanel) throws TimeoutException { preventWidgetWasNullInCIEnvironment(); - + if(_cxSettingsDefined) return; - + if(!openFromInitialPanel) { _bot.menu(TAB_WINDOW).menu(ITEM_PREFERENCES).click(); _bot.shell(ITEM_PREFERENCES).activate(); @@ -160,43 +160,43 @@ protected void testSuccessfulConnection(boolean openFromInitialPanel) throws Tim _bot.sleep(1000); _bot.shell(ITEM_PREFERENCES).setFocus(); // Need to set focus to avoid failing in CI environment - + _bot.textWithLabel(PluginConstants.PREFERENCES_API_KEY).setText(Environment.API_KEY); _bot.button(BTN_APPLY).click(); _bot.button(BTN_TEST_CONNECTION).click(); - + //Do waitUntil Method to get text from text(6) waitForConnectionResponse(); - + _bot.shell(ITEM_PREFERENCES).setFocus(); // Need to set focus to avoid failing in CI environment _bot.button(BTN_APPLY_AND_CLOSE).click(); _cxSettingsDefined = true; } - + /** * Add Checkmarx plugin in the show view perspective - * - * @throws TimeoutException + * + * @throws TimeoutException */ protected void addCheckmarxPlugin(boolean waitUntilPluginEnable) throws TimeoutException { preventWidgetWasNullInCIEnvironment(); - + _bot.menu(TAB_WINDOW).menu(ITEM_SHOW_VIEW).menu(ITEM_OTHER).click(); _bot.shell(ITEM_SHOW_VIEW).activate(); _bot.tree().expandNode(ITEM_CHECKMARX).select(ITEM_CHECKMARX_AST_SCAN); _bot.button(BTN_OPEN).click(); - + if(waitUntilPluginEnable) { - waitUntilBranchComboIsEnabled(); + waitUntilBranchComboIsEnabled(); } } - + /** * Wait while tree node equals to a a specific message. Fails after 10 retries - * + * * @param nodeText * @throws TimeoutException */ @@ -218,22 +218,22 @@ protected static void waitWhileTreeNodeEqualsTo(String nodeText) throws TimeoutE throw new TimeoutException("Timeout after 5000ms. Scan results should be retrieved"); } } - + /** * Wait until branch combobox is enabled - * + * * @throws TimeoutException */ protected static void waitUntilBranchComboIsEnabled() throws TimeoutException { preventWidgetWasNullInCIEnvironment(); - + boolean emptyScanId = _bot.comboBox(2).getText().isEmpty() || _bot.comboBox(2).getText().equals(PluginConstants.COMBOBOX_SCAND_ID_PLACEHOLDER); boolean projectNotSelected =_bot.comboBox(0).getText().isEmpty() || _bot.comboBox(0).getText().equals("Select a project"); - + if(emptyScanId || projectNotSelected) { return; } - + int retryIdx = 0; while (!_bot.comboBox(1).isEnabled()) { @@ -250,18 +250,18 @@ protected static void waitUntilBranchComboIsEnabled() throws TimeoutException { if (retryIdx == 10) { emptyScanId = _bot.comboBox(2).getText().isEmpty() || _bot.comboBox(2).getText().equals(PluginConstants.COMBOBOX_SCAND_ID_PLACEHOLDER); projectNotSelected = _bot.comboBox(0).getText().isEmpty() || _bot.comboBox(0).getText().equals("Select a project"); - + if(emptyScanId || projectNotSelected) { return; } - + throw new TimeoutException("Timeout after 5000ms. Branches' combobox must be enabled"); } } - + /** * Wait while tree node equals to a a specific message. Fails after 10 retries - * + * * @param nodeText * @throws TimeoutException */ @@ -280,31 +280,22 @@ protected static void waitForConnectionResponse() throws TimeoutException { throw new TimeoutException("Connection validation timeout after 10000ms."); } } - + /** * Type a valid Scan ID to get results - * - * @throws TimeoutException + * + * @throws TimeoutException */ private void typeValidScanID() throws TimeoutException { preventWidgetWasNullInCIEnvironment(); - - String scanId = System.getenv("SCAN_ID"); - String scanId2 = System.getenv("CX_TEST_SCAN"); - String scanId3 = Environment.SCAN_ID; - - if (scanId == null || scanId2 == null || scanId3 == null) { - throw new IllegalArgumentException("Environment variable Environment.SCAN_ID is not set. Value: " + scanId - + "Environment variable SCAN_ID2 is not set. Value: " + scanId2 + "Environment variable SCAN_ID3 is not set. Value: " + scanId3); - } - + _bot.comboBox(2).setText(Environment.SCAN_ID); _bot.comboBox(2).pressShortcut(Keystrokes.LF); - + waitUntilBranchComboIsEnabled(); } - + /** * Create a eclipse project */ @@ -314,14 +305,14 @@ private static void createEclipseProject() { shell.activate(); _bot.tree().select("Project"); _bot.button("Next >").click(); - - + + _bot.textWithLabel("Project name:").setText("MyFirstProject"); _bot.button("Finish").click(); - + _bot.menu("File").menu("New").menu("File").click(); _bot.textWithLabel("File name:").setText("Dockerfile"); _bot.tree().select(0); _bot.button("Finish").click(); } -} \ No newline at end of file +} From c99ae6373bf8cca077e6802cc3179b87d623d0c7 Mon Sep 17 00:00:00 2001 From: elchnanarbiv <45004411+elchnanarbiv@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:43:11 +0200 Subject: [PATCH 10/11] trigger pipe --- .../java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index 4e132aa..34df1a2 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -60,7 +60,7 @@ public static void beforeClass() throws Exception { // Used to decrease tests velocity SWTBotPreferences.PLAYBACK_DELAY = 100; - SWTBotPreferences.TIMEOUT = 15000; + SWTBotPreferences.TIMEOUT = 8000; _bot = new SWTWorkbenchBot(); From 1572ac0a33416ecbe3cdae748de0fc8cc980f634 Mon Sep 17 00:00:00 2001 From: elchnanarbiv <45004411+elchnanarbiv@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:18:21 +0200 Subject: [PATCH 11/11] increase timeout --- .../ast/eclipse/plugin/tests/ui/BaseUITest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index 34df1a2..b2e6785 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -58,9 +58,9 @@ public static void beforeClass() throws Exception { SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; // Used to decrease tests velocity - SWTBotPreferences.PLAYBACK_DELAY = 100; + SWTBotPreferences.PLAYBACK_DELAY = 500; - SWTBotPreferences.TIMEOUT = 8000; + SWTBotPreferences.TIMEOUT = 20000; _bot = new SWTWorkbenchBot(); @@ -205,11 +205,11 @@ protected static void waitWhileTreeNodeEqualsTo(String nodeText) throws TimeoutE while (_bot.tree().getAllItems()[0].getText().equals(nodeText)) { - if (retryIdx == 10) { + if (retryIdx == 20) { break; } - _bot.sleep(1000); + _bot.sleep(1500); retryIdx++; } @@ -238,7 +238,7 @@ protected static void waitUntilBranchComboIsEnabled() throws TimeoutException { while (!_bot.comboBox(1).isEnabled()) { - if (retryIdx == 10) { + if (retryIdx == 15) { break; }