Skip to content

Commit 06d7083

Browse files
brusdevgemmellr
authored andcommitted
ARTEMIS-5910 Fix TabsTest visibility validations
Use the same locator to validate negative and positive visibility validations.
1 parent ccd3d57 commit 06d7083

File tree

1 file changed

+43
-71
lines changed
  • tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console

1 file changed

+43
-71
lines changed

tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/TabsTest.java

Lines changed: 43 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,103 +16,75 @@
1616
*/
1717
package org.apache.activemq.artemis.tests.smoke.console;
1818

19+
import static org.junit.jupiter.api.Assertions.assertEquals;
1920
import static org.junit.jupiter.api.Assertions.fail;
2021

2122
import org.apache.activemq.artemis.tests.extensions.parameterized.ParameterizedTestExtension;
2223
import org.apache.activemq.artemis.tests.smoke.console.pages.LoginPage;
24+
import org.apache.activemq.artemis.tests.smoke.console.pages.StatusPage;
2325
import org.junit.jupiter.api.TestTemplate;
2426
import org.junit.jupiter.api.extension.ExtendWith;
2527
import org.openqa.selenium.By;
2628
import org.openqa.selenium.NoSuchElementException;
2729

30+
import java.util.Collections;
31+
import java.util.Set;
32+
2833
//Parameters set in super class
2934
@ExtendWith(ParameterizedTestExtension.class)
3035
public class TabsTest extends ArtemisTest {
3136

32-
public TabsTest(String browser, String serverName) {
33-
super(browser, serverName);
34-
}
35-
36-
@TestTemplate
37-
public void testConnectionsTab() {
38-
testTab("connections", "Connections");
39-
}
40-
41-
@TestTemplate
42-
public void testSessionsTab() {
43-
testTab("sessions", "Sessions");
44-
}
45-
46-
@TestTemplate
47-
public void testConsumersTab() {
48-
testTab("consumers", "Consumers");
49-
}
50-
51-
@TestTemplate
52-
public void testProducersTab() {
53-
testTab("producers", "Producers");
54-
}
55-
56-
@TestTemplate
57-
public void testAddressesTab() {
58-
testTab("addresses", "Addresses");
59-
}
37+
private final String TAB_CONNECTIONS = "Connections";
6038

61-
@TestTemplate
62-
public void testQueuesTab() {
63-
testTab("queues", "Queues");
64-
}
39+
private final String TAB_SESSIONS = "Sessions";
6540

66-
private void testTab(String userpass, String tab) {
67-
loadLandingPage();
68-
new LoginPage(driver).loginValidUser(userpass, userpass, DEFAULT_TIMEOUT);
69-
driver.findElement(By.xpath("//button/span[contains(text(),'" + tab + "')]"));
70-
}
41+
private final String TAB_CONSUMERS = "Consumers";
7142

72-
@TestTemplate
73-
public void testConnectionsTabNegative() {
74-
// use credentials for a valid user who cannot see the tab
75-
testTabNegative("queues", "Connections");
76-
}
43+
private final String TAB_PRODUCERS = "Producers";
7744

78-
@TestTemplate
79-
public void testSessionsTabNegative() {
80-
// use credentials for a valid user who cannot see the tab
81-
testTabNegative("connections", "Sessions");
82-
}
45+
private final String TAB_ADDRESSES = "Addresses";
8346

84-
@TestTemplate
85-
public void testConsumersTabNegative() {
86-
// use credentials for a valid user who cannot see the tab
87-
testTabNegative("connections", "Consumers");
88-
}
47+
private final String TAB_QUEUES = "Queues";
8948

90-
@TestTemplate
91-
public void testProducersTabNegative() {
92-
// use credentials for a valid user who cannot see the tab
93-
testTabNegative("connections", "roducers");
94-
}
49+
private final String[] TABS = new String[]{TAB_CONNECTIONS, TAB_SESSIONS, TAB_CONSUMERS, TAB_PRODUCERS, TAB_ADDRESSES, TAB_QUEUES};
9550

96-
@TestTemplate
97-
public void testAddressesTabNegative() {
98-
// use credentials for a valid user who cannot see the tab
99-
testTabNegative("connections", "Addresses");
51+
public TabsTest(String browser, String serverName) {
52+
super(browser, serverName);
10053
}
10154

10255
@TestTemplate
103-
public void testQueuesTabNegative() {
104-
// use credentials for a valid user who cannot see the tab
105-
testTabNegative("connections", "Queues");
56+
public void testVisibleTabs() {
57+
testTabs(SERVER_ADMIN_USERNAME, false, Set.of(TABS));
58+
testTabs("connections", true, Collections.singleton(TAB_CONNECTIONS));
59+
testTabs("sessions", true, Collections.singleton(TAB_SESSIONS));
60+
testTabs("consumers", true, Collections.singleton(TAB_CONSUMERS));
61+
testTabs("producers", true, Collections.singleton(TAB_PRODUCERS));
62+
testTabs("addresses", true, Collections.singleton(TAB_ADDRESSES));
63+
testTabs("queues", true, Collections.singleton(TAB_QUEUES));
10664
}
10765

108-
private void testTabNegative(String userpass, String tab) {
66+
private void testTabs(String userpass, boolean isAlertExpected, Set<String> visibleTabs) {
10967
loadLandingPage();
110-
new LoginPage(driver).loginValidUser(userpass, userpass, DEFAULT_TIMEOUT);
111-
try {
112-
driver.findElement(By.xpath("//a[contains(text(),'" + tab + "')]"));
113-
fail("User " + userpass + " should not have been able to see the " + tab + " tab.");
114-
} catch (NoSuchElementException e) {
115-
// expected
68+
69+
StatusPage statusPage = new LoginPage(driver).loginValidUser(userpass, userpass, DEFAULT_TIMEOUT);
70+
71+
assertEquals(isAlertExpected, statusPage.countAlerts() > 0);
72+
statusPage.closeAlerts();
73+
74+
for (String tab : TABS) {
75+
By tabLocator = By.xpath("//button/span[contains(text(),'" + tab + "')]");
76+
if (visibleTabs.contains(tab)) {
77+
driver.findElement(tabLocator);
78+
} else {
79+
try {
80+
driver.findElement(tabLocator);
81+
fail("User " + userpass + " should not have been able to see the " + tab + " tab.");
82+
} catch (Exception e) {
83+
assertEquals(NoSuchElementException.class, e.getClass());
84+
}
85+
}
11686
}
87+
88+
statusPage.logout(DEFAULT_TIMEOUT);
11789
}
11890
}

0 commit comments

Comments
 (0)