Skip to content

Commit 35ac964

Browse files
author
Anders Breid
authored
Subscription improvements (#100)
* Default values for notification message is set to "Rest Post" and "Raw JSON Body". * Default values for repeat is set to "False". * Notification message and meta type is set using radio buttons where you select between the 2 oprions. * The repeat is set using a checkbox covered by a sliding bar indicating On or Off. * After switching back end the page is reloaded before the subscription page was loaded and back end list was updated, the later did not work well. * Geckodriver for tests windows updated * Added email validation when adding subscription * logged in/ logged out status now updates and display correctly when switching back end. * 2.5C is the best and by surefire recommended forkCount for 4 core CPUś pom updated. * If switching back end fails, the gui will display the last used back end in list, so user do not believe the back end was switched.
1 parent 41307bf commit 35ac964

File tree

11 files changed

+651
-495
lines changed

11 files changed

+651
-495
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
<artifactId>maven-surefire-plugin</artifactId>
153153
<version>2.20</version>
154154
<configuration>
155-
<forkCount>2C</forkCount>
155+
<forkCount>2.5C</forkCount>
156156
<reuseForks>false</reuseForks>
157157
<useSystemClassLoader>false</useSystemClassLoader>
158158
<excludes>

src/functionaltest/java/com/ericsson/ei/frontend/TestSubscriptionHandling.java

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,17 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
5353
// present AND there exists "edit" and" delete buttons" for unauthorized
5454
// user "ABCD"
5555
String response = getJSONStringFromFile(SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH);
56-
String viewButtonXPath = "(//button[@id='view-Subscription1'])[2]";
57-
String editButtonXPath = "(//button[@id='edit-Subscription1'])[2]";
58-
String deleteButtonXPath = "(//button[@id='delete-Subscription1'])[2]";
59-
String expandButtonXPath = "//tr[contains(.,'Subscription1')]/td[1]";
6056

6157
subscriptionPage.clickReload(response);
6258

63-
assert (subscriptionPage.textExistsInTable("Subscription1"));
64-
assert (subscriptionPage.textExistsInTable("Subscription2"));
65-
assert (subscriptionPage.clickElementByXPath(expandButtonXPath));
66-
assert (subscriptionPage.buttonExist(deleteButtonXPath));
67-
assert (subscriptionPage.buttonExist(editButtonXPath));
68-
assert (subscriptionPage.buttonExist(viewButtonXPath));
59+
String expandButtonXPath = "//tr[contains(.,'Subscription1')]/td[1]";
60+
String viewButtonXPath = "(//button[@id='view-Subscription1'])";
61+
String editButtonXPath = "(//button[@id='edit-Subscription1'])";
62+
String deleteButtonXPath = "(//button[@id='delete-Subscription1'])";
63+
assert (subscriptionPage.clickExpandButtonByXPath(expandButtonXPath));
64+
assert (subscriptionPage.buttonExistByXPath(deleteButtonXPath));
65+
assert (subscriptionPage.buttonExistByXPath(editButtonXPath));
66+
assert (subscriptionPage.buttonExistByXPath(viewButtonXPath));
6967

7068
// Given LDAP is enabled, "Reload" subscriptions and then click
7169
// subscription page with LDAP enabled with unauthorized user names
@@ -76,10 +74,10 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
7674
subscriptionPage.clickReloadLDAP(responseSub, responseAuth);
7775
indexPageObject.clickSubscriptionPage();
7876

79-
assert (subscriptionPage.clickElementByXPath(expandButtonXPath));
80-
assert (!subscriptionPage.buttonExist(deleteButtonXPath));
81-
assert (!subscriptionPage.buttonExist(editButtonXPath));
82-
assert (subscriptionPage.buttonExist(viewButtonXPath));
77+
assert (subscriptionPage.clickExpandButtonByXPath(expandButtonXPath));
78+
assert (!subscriptionPage.buttonExistByXPath(deleteButtonXPath));
79+
assert (!subscriptionPage.buttonExistByXPath(editButtonXPath));
80+
assert (subscriptionPage.buttonExistByXPath(viewButtonXPath));
8381

8482
// Given LDAP is enabled, "Reload" subscriptions and then click
8583
// subscription page with LDAP enabled with both unauthorized and
@@ -95,25 +93,26 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
9593
indexPageObject.clickSubscriptionPage();
9694

9795
assert (subscriptionPage.textExistsInTable("Subscription1"));
98-
assert (subscriptionPage.clickElementByXPath(expandButtonXPath));
99-
assert (subscriptionPage.buttonExist(deleteButtonXPath));
100-
assert (subscriptionPage.buttonExist(editButtonXPath));
101-
assert (subscriptionPage.buttonExist(viewButtonXPath));
96+
assert (subscriptionPage.clickExpandButtonByXPath(expandButtonXPath));
97+
assert (subscriptionPage.buttonExistByXPath(deleteButtonXPath));
98+
assert (subscriptionPage.buttonExistByXPath(editButtonXPath));
99+
assert (subscriptionPage.buttonExistByXPath(viewButtonXPath));
102100

103101
// Now, path for "subscriptions2" with user name "DEF", so user "ABCD"
104102
// is unauthorized for this subscription
105-
String viewButtonXPath2 = "(//button[@id='view-Subscription2'])[2]";
106-
String editButtonXPath2 = "(//button[@id='edit-Subscription2'])[2]";
107-
String deleteButtonXPath2 = "(//button[@id='delete-Subscription2'])[2]";
103+
String viewButtonXPath2 = "(//button[@id='view-Subscription2'])";
104+
String editButtonXPath2 = "(//button[@id='edit-Subscription2'])";
105+
String deleteButtonXPath2 = "(//button[@id='delete-Subscription2'])";
108106
String expandButtonXPath2 = "//tr[contains(.,'Subscription2')]/td[1]";
109107

110-
assert (subscriptionPage.clickElementByXPath(expandButtonXPath2));
111-
assert (subscriptionPage.buttonExist(viewButtonXPath2));
112-
assert (!subscriptionPage.buttonExist(editButtonXPath2));
113-
assert (!subscriptionPage.buttonExist(deleteButtonXPath2));
108+
assert (subscriptionPage.clickExpandButtonByXPath(expandButtonXPath2));
109+
assert (subscriptionPage.buttonExistByXPath(viewButtonXPath2));
110+
subscriptionPage.clickViewButtonByXPath(viewButtonXPath2);
111+
assert (!subscriptionPage.buttonExistByXPath(editButtonXPath2));
112+
assert (!subscriptionPage.buttonExistByXPath(deleteButtonXPath2));
114113

115114
// Test view button
116-
subscriptionPage.clickElementByXPath(viewButtonXPath2);
115+
subscriptionPage.clickViewButtonByXPath(viewButtonXPath2);
117116
assert (new WebDriverWait(driver, 10)
118117
.until((webdriver) -> driver.getPageSource().contains("View Subscription")));
119118
subscriptionPage.clickFormCloseBtn();
@@ -163,29 +162,34 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
163162
// On subscription form, select the template as "Mail Trigger" and
164163
// verify
165164
String selectID = "selectTemplate";
165+
String mailRadioID = "mailRadio";
166+
String notificationMetaInputID = "notificationMeta";
166167
String tempMail = "Mail Trigger";
167168
subscriptionPage.selectDropdown(selectID, tempMail);
168-
assert (new WebDriverWait(driver, 10)
169-
.until((webdriver) -> (subscriptionPage.getValueFromSelect().equals("MAIL"))));
170-
assert (new WebDriverWait(driver, 10)
171-
.until((webdriver) -> (subscriptionPage.getValueFromElement().equals("mymail@company.com"))));
169+
assert (subscriptionPage.isRadioCheckboxSelected(mailRadioID));
170+
assertEquals ("mymail@company.com", subscriptionPage.getValueFromElement(notificationMetaInputID));
172171

173172
// On subscription form, select the template as "REST POST (Raw
174173
// Body:JSON)" and verify
175174
String tempPost = "REST POST (Raw Body : JSON)";
175+
String restPostRadio = "restPostRadio";
176+
String keyValueRadio = "keyValueRadio";
177+
String appJsonRadio = "appJsonRadio";
176178
subscriptionPage.selectDropdown(selectID, tempPost);
177-
assert (new WebDriverWait(driver, 10)
178-
.until((webdriver) -> (subscriptionPage.getValueFromSelect().equals("REST_POST"))));
179-
assert (new WebDriverWait(driver, 10).until(
180-
(webdriver) -> (subscriptionPage.getValueFromElement().equals("http://<MyHost:port>/api/doit"))));
179+
assert (subscriptionPage.isRadioCheckboxSelected(restPostRadio));
180+
assert (subscriptionPage.isRadioCheckboxSelected(appJsonRadio));
181+
assert (!subscriptionPage.isRadioCheckboxSelected(keyValueRadio));
182+
assertEquals ("http://<MyHost:port>/api/doit", subscriptionPage.getValueFromElement(notificationMetaInputID));
181183

182184
// On subscription form, select the template as "Jenkins Pipeline
183-
// Parameterized Job Trigger" and verify
185+
// Parameterized Job Trigger" and verify RawBody unselected.
184186
String tempJenkins = "Jenkins Pipeline Parameterized Job Trigger";
185187
subscriptionPage.selectDropdown(selectID, tempJenkins);
186-
assertEquals("REST_POST", subscriptionPage.getValueFromSelect());
188+
assert (subscriptionPage.isRadioCheckboxSelected(restPostRadio));
189+
assert (subscriptionPage.isRadioCheckboxSelected(keyValueRadio));
190+
assert (!subscriptionPage.isRadioCheckboxSelected(appJsonRadio));
187191
assertEquals("http://<JenkinsHost:port>/job/<JobName>/job/<branch>/build",
188-
subscriptionPage.getValueFromElement());
192+
subscriptionPage.getValueFromElement(notificationMetaInputID));
189193

190194
// Choose Authorization as "Basic_AUTH" ===> input User Name as "ABCD"
191195
// and Token as "EFGH" ===> click "Generate Key/Value Pair", verify the
@@ -196,43 +200,37 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
196200
String userNameID = "userNameInput";
197201
String password = "password";
198202
String passwordID = "passwordInput";
199-
String subName = "Selenium_test_subscription";
200-
String subNameID = "subscriptionNameInput";
201-
String selectRepeatID = "selectRepeat";
202-
String repeatValue = "true";
203-
String conditionFieldID = "conditionID";
204-
String requirementFieldID = "requirementID";
205-
206203
subscriptionPage.selectDropdown(selectAuthID, authValue);
207204
subscriptionPage.addFieldValue(userNameID, userName);
208205
subscriptionPage.addFieldValue(passwordID, password);
209206

210207
assert (new WebDriverWait(driver, 10).until((webdriver) -> driver.getPageSource().contains("ABCD")));
211208
assert (new WebDriverWait(driver, 10).until((webdriver) -> driver.getPageSource().contains("password")));
212209

213-
// Test "Repeat" dropdown: Select repeat value as "true" and then verify the selected value
214-
subscriptionPage.selectDropdown(selectRepeatID, repeatValue);
215-
assert (new WebDriverWait(driver, 10)
216-
.until((webdriver) -> (subscriptionPage.getValueFromSelectRepeat().equals(repeatValue))));
210+
// Test "Repeat" checkbox: verify unchecked, then checked.
211+
// NOTE: repeat checkbox is covered by a span, we click span
212+
String checkboxRepeatID = "repeatCheckbox";
213+
String spanId = "repeatCheckboxSpan";
214+
assert (!subscriptionPage.isCheckboxSelected(checkboxRepeatID));
215+
subscriptionPage.clickSpanAroundCheckbox(checkboxRepeatID, spanId);
216+
assert (subscriptionPage.isCheckboxSelected(checkboxRepeatID));
217217

218218
// Test "Add Condition" button: click add condition button and check that it adds an additional "condition" field
219+
String conditionFieldID = "conditionID";
219220
subscriptionPage.clickAddConditionBtn();
220221
assertEquals(2, subscriptionPage.countElements(conditionFieldID));
221222

222223
// Test "Add Requirement" button: click the button and assert that it adds an additional "requirement" field
224+
String requirementFieldID = "requirementID";
223225
subscriptionPage.clickAddRequirementBtn();
224226
assertEquals(2, subscriptionPage.countElements(requirementFieldID));
225227

226-
// Test "Repeat" dropdown: Select repeat value as "true" and then verify
227-
// the selected value
228-
subscriptionPage.selectDropdown(selectRepeatID, repeatValue);
229-
assert (new WebDriverWait(driver, 10)
230-
.until((webdriver) -> (subscriptionPage.getValueFromSelectRepeat().equals(repeatValue))));
231-
232228
// Test save subscription form: add subscription name
233229
// as "selenium_test_subscription" and then click "save" button
234230
// verification that subscription is added in the datatable (and is
235231
// displayed on the main page)
232+
String subName = "Selenium_test_subscription";
233+
String subNameID = "subscriptionNameInput";
236234
String responseSave = getJSONStringFromFile(SUBSCRIPTION_FOR_SAVE_TEST_FILE_PATH);
237235
subscriptionPage.addFieldValue(subNameID, subName);
238236
subscriptionPage.clickFormsSaveBtn(responseSave);

src/functionaltest/java/com/ericsson/ei/frontend/pageobjects/SubscriptionPage.java

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,48 @@ public void selectDropdown(String loc, String value) {
101101
dropdown.selectByVisibleText(value);
102102
}
103103

104-
public String getValueFromSelect() {
104+
public boolean isRadioCheckboxSelected(String id) {
105105
new WebDriverWait(driver, TIMEOUT_TIMER)
106-
.until(ExpectedConditions.elementToBeClickable(By.id("notificationType")));
107-
WebElement selectNotificationType = driver.findElement(By.id("notificationType"));
108-
Select dropdown = new Select(selectNotificationType);
109-
return dropdown.getFirstSelectedOption().getText();
106+
.until(ExpectedConditions.elementToBeClickable(By.id(id)));
107+
WebElement checkbox = driver.findElement(By.id(id));
108+
boolean radioBtnIsSelected = checkbox.isSelected();
109+
return radioBtnIsSelected;
110+
}
111+
112+
public boolean isCheckboxSelected(String id) {
113+
new WebDriverWait(driver, TIMEOUT_TIMER)
114+
.until(ExpectedConditions.presenceOfElementLocated(By.id(id)));
115+
WebElement checkbox = driver.findElement(By.id(id));
116+
boolean isSelected = checkbox.isSelected();
117+
return isSelected;
118+
}
119+
120+
public void clickSpanAroundCheckbox(String id, String spanId) {
121+
new WebDriverWait(driver, TIMEOUT_TIMER)
122+
.until(ExpectedConditions.presenceOfElementLocated(By.id(id)));
123+
new WebDriverWait(driver, TIMEOUT_TIMER)
124+
.until(ExpectedConditions.presenceOfElementLocated(By.id(spanId)));
125+
126+
WebElement checkbox = driver.findElement(By.id(id));
127+
WebElement span = driver.findElement(By.id(spanId));
128+
129+
span.click();
130+
131+
new WebDriverWait(driver, TIMEOUT_TIMER)
132+
.until(ExpectedConditions.elementSelectionStateToBe(checkbox, true));
110133
}
111-
112-
public String getValueFromSelectRepeat() {
134+
135+
public String getValueFromSelect(String id) {
113136
new WebDriverWait(driver, TIMEOUT_TIMER)
114-
.until(ExpectedConditions.elementToBeClickable(By.id("selectRepeat")));
115-
WebElement selectNotificationType = driver.findElement(By.id("selectRepeat"));
137+
.until(ExpectedConditions.elementToBeClickable(By.id(id)));
138+
WebElement selectNotificationType = driver.findElement(By.id(id));
116139
Select dropdown = new Select(selectNotificationType);
117140
return dropdown.getFirstSelectedOption().getText();
118141
}
119142

120-
public String getValueFromElement() {
121-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("metaData")));
122-
WebElement metaTxt = driver.findElement(By.id("metaData"));
143+
public String getValueFromElement(String id) {
144+
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id(id)));
145+
WebElement metaTxt = driver.findElement(By.id(id));
123146
return metaTxt.getAttribute("value");
124147
}
125148

@@ -172,13 +195,13 @@ public void clickFormCloseBtn() {
172195
WebElement viewBtn = driver.findElement(By.className("close"));
173196
viewBtn.click();
174197
}
175-
198+
176199
public void clickAddConditionBtn() {
177200
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("addCondition")));
178201
WebElement viewBtn = driver.findElement(By.id("addCondition"));
179202
viewBtn.click();
180203
}
181-
204+
182205
public void clickAddRequirementBtn(){
183206
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("addRequirement")));
184207
WebElement viewBtn = driver.findElement(By.id("addRequirement"));
@@ -192,15 +215,34 @@ public String getSubscriptionNameFromSubscription() {
192215
return subscriptionNameElement.getText();
193216
}
194217

195-
public boolean buttonExist(String loc) {
218+
public boolean expandButtonExist(String XPath) {
196219
try {
197-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.xpath(loc)));
220+
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.xpath(XPath)));
198221
} catch (Exception e) {
199222
return false;
200223
}
201224
return true;
202225
}
203226

227+
public boolean buttonExistByXPath(String XPath) {
228+
// The row indicates weather or not the del / view and edit buttons has moved down to
229+
// next row.
230+
String findInRow;
231+
try {
232+
findInRow = "[2]";
233+
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.xpath(XPath + findInRow)));
234+
return true;
235+
} catch (Exception e) {
236+
}
237+
try {
238+
findInRow = "[1]";
239+
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.xpath(XPath + findInRow)));
240+
return true;
241+
} catch (Exception e) {
242+
}
243+
return false;
244+
}
245+
204246
public void clickReloadLDAP(String response, String responseAuth) throws IOException {
205247
CloseableHttpResponse responseData = this.createMockedHTTPResponse(response, 200);
206248
CloseableHttpResponse responseDataAuth = this.createMockedHTTPResponse(responseAuth, 200);
@@ -222,17 +264,41 @@ public boolean textExistsInTable(String txt) {
222264
return true;
223265
}
224266

225-
public boolean clickElementByXPath(String loc) {
267+
public boolean clickExpandButtonByXPath(String loc) {
226268
try {
227-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.xpath(loc)));
228-
driver.findElement(By.xpath(loc)).click();
269+
if (expandButtonExist(loc)) {
270+
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.xpath(loc)));
271+
driver.findElement(By.xpath(loc)).click();
272+
} else {
273+
return true;
274+
}
229275
} catch (Exception e) {
230276
return false;
231277
}
232278
return true;
233279
}
234-
280+
235281
public int countElements(String id) {
236-
return driver.findElements(By.id(id)).size();
282+
return driver.findElements(By.id(id)).size();
237283
}
284+
285+
public void clickViewButtonByXPath(String XPath) {
286+
// The row indicates weather or not the del / view and edit buttons has moved down to
287+
// next row.
288+
try {
289+
String Xpath2 = XPath + "[2]";
290+
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.xpath(Xpath2)));
291+
driver.findElement(By.xpath(Xpath2)).click();
292+
return;
293+
} catch (Exception e) {
294+
}
295+
try {
296+
String Xpath1 = XPath + "[1]";
297+
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.xpath(Xpath1)));
298+
driver.findElement(By.xpath(Xpath1)).click();
299+
return;
300+
} catch (Exception e) {
301+
}
302+
}
303+
238304
}
6.95 MB
Binary file not shown.

0 commit comments

Comments
 (0)