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

deprecate unstable locator methods #1183

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/e2e-test/features/logviewer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Feature: Logviewer - Validate log viewer functionalities

@LOGVIEWER_TEST
Scenario: Log viewer content should contain correct information
Then Deployed pipeline status is "Succeeded"
Then Click on log viewer button
Then Log viewer content should contain message "is started by user"
Then Log viewer content should not contain message "This is a WARN"
Expand Down
2 changes: 1 addition & 1 deletion src/e2e-test/fixtures/logs_generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"scope": "SYSTEM"
},
"properties": {
"script": "/**\n * @summary Transforms the provided input record into zero or more output records or errors.\n\n * Input records are available in JavaScript code as JSON objects. \n\n * @param input an object that contains the input record as a JSON. e.g. to access a field called 'total' from the input record, use input.total.\n * @param emitter an object that can be used to emit zero or more records (using the emitter.emit() method) or errors (using the emitter.emitError() method) \n * @param context an object that provides access to:\n * 1. CDAP Metrics - context.getMetrics().count('output', 1);\n * 2. CDAP Logs - context.getLogger().debug('Received a record');\n * 3. Lookups - context.getLookup('blacklist').lookup(input.id); or\n * 4. Runtime Arguments - context.getArguments().get('priceThreshold') \n */ \nfunction transform(input, emitter, context) {\n /**\n * Delay for a number of milliseconds\n */\n function sleep(delay) {\n var start = new Date().getTime();\n while (new Date().getTime() < start + delay);\n }\n \n sleep(15000);\n var split = input.body.split(',');\n var logger = context.getLogger();\n logger.warn('This is a WARN');\n for (var i = 0; i < 100; i++) {\n logger.debug('DEBUG ' + split[0] + ' ' + i);\n }\n \n emitter.emit(input);\n}",
"script": "/**\n * @summary Transforms the provided input record into zero or more output records or errors.\n\n * Input records are available in JavaScript code as JSON objects. \n\n * @param input an object that contains the input record as a JSON. e.g. to access a field called 'total' from the input record, use input.total.\n * @param emitter an object that can be used to emit zero or more records (using the emitter.emit() method) or errors (using the emitter.emitError() method) \n * @param context an object that provides access to:\n * 1. CDAP Metrics - context.getMetrics().count('output', 1);\n * 2. CDAP Logs - context.getLogger().debug('Received a record');\n * 3. Lookups - context.getLookup('blacklist').lookup(input.id); or\n * 4. Runtime Arguments - context.getArguments().get('priceThreshold') \n */ \nfunction transform(input, emitter, context) {\n /**\n * Delay for a number of milliseconds\n */\n function sleep(delay) {\n var start = new Date().getTime();\n while (new Date().getTime() < start + delay);\n }\n \n sleep(1000);\n var split = input.body.split(',');\n var logger = context.getLogger();\n logger.warn('This is a WARN');\n for (var i = 0; i < 100; i++) {\n logger.debug('DEBUG ' + split[0] + ' ' + i);\n }\n \n emitter.emit(input);\n}",
"schema": "{\"type\":\"record\",\"name\":\"etlSchemaBody\",\"fields\":[{\"name\":\"body\",\"type\":\"string\"}]}"
}
},
Expand Down
16 changes: 6 additions & 10 deletions src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/Logviewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,16 @@ public void logLevelItemCheckShouldNotExist(String item) {

@Then("Log viewer content should contain message {string}")
public void logViewerContentMessageExists(String message) {
Assert.assertTrue(
Helper.isElementExists(
By.xpath("//div[@data-testid='log-viewer-content']//*[contains(text(), '" + message + "')]")
)
);
Assert.assertTrue(Helper.isElementExistsByTestid("log-viewer-content"));
WebElement logViewerContentElement = Helper.locateElementByTestId("log-viewer-content");
Assert.assertTrue(logViewerContentElement.getText().contains(message));
}

@Then("Log viewer content should not contain message {string}")
public void logViewerContentMessageNotExists(String message) {
Assert.assertFalse(
Helper.isElementExists(
By.xpath("//div[@data-testid='log-viewer-content']//*[contains(text(), '" + message + "')]")
)
);
Assert.assertTrue(Helper.isElementExistsByTestid("log-viewer-content"));
WebElement logViewerContentElement = Helper.locateElementByTestId("log-viewer-content");
Assert.assertFalse(logViewerContentElement.getText().contains(message));
}

@Then("Click on advanced logs")
Expand Down
12 changes: 8 additions & 4 deletions src/e2e-test/java/io/cdap/cdap/ui/utils/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ public static void openPluginGroupPanel(String pluginGroup) {
"//div[@data-testid='plugin-" + pluginGroup + "-group-summary' and @aria-expanded='false']"));
WaitHelper.waitForElementToBeDisplayed(Helper.locateElementByTestId("plugin-" + pluginGroup + "-group-details"));
} catch (StaleElementReferenceException | NoSuchElementException e) {
Assert.assertTrue(Helper.isElementExists(
By.xpath("//div[@data-testid='plugin-" + pluginGroup + "-group-summary' and @aria-expanded='true']")));
String testid = "plugin-" + pluginGroup + "-group-summary";
Assert.assertTrue(Helper.isElementExistsByTestid(testid));
WebElement pluginGroupSummaryElement = Helper.locateElementByTestId(testid);
Assert.assertTrue(pluginGroupSummaryElement.getAttribute("aria-expanded").equals("true"));
}
}

Expand All @@ -207,8 +209,10 @@ public static void closePluginGroupPanel(String pluginGroup) {
"//div[@data-testid='plugin-" + pluginGroup + "-group-summary' and @aria-expanded='false']")
);
} catch (StaleElementReferenceException | NoSuchElementException e) {
Assert.assertTrue(Helper.isElementExists(
By.xpath("//div[@data-testid='plugin-" + pluginGroup + "-group-summary' and @aria-expanded='false']")));
String testid = "plugin-" + pluginGroup + "-group-summary";
Assert.assertTrue(Helper.isElementExistsByTestid(testid));
WebElement pluginGroupSummaryElement = Helper.locateElementByTestId(testid);
Assert.assertTrue(pluginGroupSummaryElement.getAttribute("aria-expanded").equals("false"));
}
}

Expand Down
22 changes: 19 additions & 3 deletions src/e2e-test/java/io/cdap/cdap/ui/utils/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public static String getSessionToken() throws IOException {
return response.getResponseBodyAsString();
}

@Deprecated
public static WebElement locateElementByCssSelector(String cssSelector) {
return SeleniumDriver.getDriver()
.findElement(By.cssSelector(cssSelector));
Expand All @@ -148,20 +149,23 @@ public static WebElement locateElementByTestId(String testId, WebElement withinE
return withinElement.findElement(By.cssSelector(Helper.getCssSelectorByDataTestId(testId)));
}

@Deprecated
public static WebElement locateElementById(String elementId) {
return SeleniumDriver.getDriver()
.findElement(By.id(elementId));
}

public static WebElement locateElementByLocator(By locator) {
private static WebElement locateElementByLocator(By locator) {
return SeleniumDriver.getDriver().findElement(locator);
}

@Deprecated
public static WebElement locateElementByXPath(String xpath) {
return SeleniumDriver.getDriver()
.findElement(By.xpath(xpath));
}

@Deprecated
public static List<WebElement> locateElementsByXPath(String xpath) {
return SeleniumDriver.getDriver().findElements(By.xpath(xpath));
}
Expand All @@ -171,26 +175,36 @@ public static List<WebElement> locateElementsByTestId(String testId) {
.findElements(By.cssSelector(Helper.getCssSelectorByDataTestId(testId)));
}

public static boolean isElementExistsByTestid(String testid) {
return isElementExists(By.cssSelector(Helper.getCssSelectorByDataTestId(testid)));
}

public static boolean isElementExistsByTestid(String testid, WebElement withinElement) {
return isElementExists(By.cssSelector(Helper.getCssSelectorByDataTestId(testid)), withinElement);
}

@Deprecated
public static boolean isElementExists(String cssSelector) {
return isElementExists(By.cssSelector(cssSelector));
}

public static boolean isElementExists(By by) {
private static boolean isElementExists(By by) {
try {
return ElementHelper.isElementDisplayed(SeleniumDriver.getDriver().findElement(by));
} catch (StaleElementReferenceException | NoSuchElementException e) {
return false;
}
}

public static boolean isElementExists(By by, WebElement withinElement) {
private static boolean isElementExists(By by, WebElement withinElement) {
try {
return ElementHelper.isElementDisplayed(withinElement.findElement(by));
} catch (StaleElementReferenceException | NoSuchElementException e) {
return false;
}
}

@Deprecated
public static boolean isElementExists(String cssSelector, WebElement withinElement) {
return isElementExists(By.cssSelector(cssSelector), withinElement);
}
Expand All @@ -213,6 +227,7 @@ public static String getNodeNameSelectorFromNodeIdentifier(NodeInfo node) {
node.getNodeId() + "\"]";
}

// TODO: this method should be refactored to use data-testid for locating elements
public static void uploadPipelineFromFile(String filename) {
String pipelineNameXPathSelector = "//div[contains(@class, 'PipelineName')]";
WebElement element = locateElementByLocator(By.xpath(pipelineNameXPathSelector));
Expand Down Expand Up @@ -289,6 +304,7 @@ public static By locatorOfPluginGroupCollapsed(String pluginGroupName) {
return By.xpath(xpath);
}

// TODO: Refactor to locate element using only testid
public static By locatorOfPluginGroupExpanded(String pluginGroupName) {
String xpath = "//div[@data-cy='plugin-" + pluginGroupName
+ "-group' and contains(@class, 'Mui-expanded')]//div[contains(@class, 'expandIcon')]";
Expand Down