Skip to content

Commit d86d145

Browse files
committed
Update tests to run them on Grafana 10
1 parent aeb1927 commit d86d145

File tree

7 files changed

+217
-83
lines changed

7 files changed

+217
-83
lines changed

tests/cypress/e2e/spec.cy.ts

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import '../support/api_commands';
2+
import CheckmkSelectors from '../support/checkmk_selectors';
23
import '../support/commands';
34

45
describe('e2e tests', () => {
@@ -12,20 +13,41 @@ describe('e2e tests', () => {
1213
const CmkCRE = 'Raw Edition';
1314

1415
const inputDatasourceId = 'data-source-picker';
15-
const inputFilterId = 'react-select-7-input';
16-
const inputGraphId = 'input_Predefined graph';
17-
const inputGraphTypeId = 'input_Graph type';
16+
const inputFilterId = CheckmkSelectors.AddDashboard.filterFieldId;
17+
const inputGraphId = 'input_Predefined_graph';
18+
const inputGraphTypeId = 'input_Graph_type';
1819
const inputHostId = 'input_Hostname';
19-
const inputMetricId = 'input_Single metric';
20+
const inputMetricId = 'input_Single_metric';
2021
const inputServiceId = 'input_Service';
2122
const inputSiteId = 'input_Site';
23+
const inputHostLabelId = CheckmkSelectors.AddDashboard.hostLabelFieldId;
2224

2325
const inputHostRegexDataTestId = 'host_name_regex-filter-input';
2426
const inputServiceRegexDataTestId = 'service_regex-filter-input';
2527

2628
const queryEditorSelector = '[class="query-editor-row"]';
2729

30+
let cmkSite = 'cmk';
31+
2832
before(() => {
33+
//Determine site name from variables
34+
const grafanaCMKSite = Cypress.env('grafanaToCheckmkUrl')
35+
? new URL(Cypress.env('grafanaToCheckmkUrl')).pathname.split('/').pop()
36+
: 'cmk';
37+
38+
const cypressCMKSite = Cypress.env('cypressToCheckmkUrl')
39+
? new URL(Cypress.env('cypressToCheckmkUrl')).pathname.split('/').pop()
40+
: 'cmk';
41+
42+
if (grafanaCMKSite !== cypressCMKSite) {
43+
console.log('Site name mismatch between grafanaToCheckmkUrl and cypressToCheckmkUrl');
44+
console.log({ grafanaCMKSite, cypressCMKSite });
45+
throw new Error('grafanaToCheckmkUrl and cypressToCheckmkUrl must have the same site name');
46+
}
47+
48+
cmkSite = grafanaCMKSite;
49+
console.log(`Site name is "${cmkSite}"`);
50+
2951
cy.deleteCmkAutomationUser(false); // clean-up possible existing user
3052
cy.createCmkAutomationUser();
3153

@@ -38,7 +60,7 @@ describe('e2e tests', () => {
3860
cy.executeServiceDiscovery(hostName0, 'fix_all');
3961
cy.executeServiceDiscovery(hostName1, 'refresh');
4062
cy.executeServiceDiscovery(hostName1, 'fix_all');
41-
cy.activateCmkChanges('cmk');
63+
cy.activateCmkChanges(cmkSite);
4264
cy.waitForPendingServices(2000);
4365

4466
cy.loginGrafana();
@@ -52,7 +74,7 @@ describe('e2e tests', () => {
5274
cy.deleteCmkHost(hostName0);
5375
cy.deleteCmkHost(hostName1);
5476
cy.deleteCmkAutomationUser(true);
55-
cy.activateCmkChanges('cmk');
77+
cy.activateCmkChanges(cmkSite);
5678
});
5779

5880
beforeEach(() => {
@@ -66,6 +88,8 @@ describe('e2e tests', () => {
6688
});
6789
describe('CEE tests', () => {
6890
it('time-usage panel by service (single host)', {}, () => {
91+
cy.selectDataSource(CmkCEE);
92+
6993
cy.contains('Checkmk ' + CmkCEE).should('be.visible'); // Assert Cmk CEE datasource is used
7094

7195
cy.inputLocatorById(inputFilterId).type('Hostname{enter}'); // Filter -> 'Host name'
@@ -100,12 +124,17 @@ describe('e2e tests', () => {
100124
});
101125

102126
it('time-usage panel by service (multiple hosts)', {}, () => {
127+
cy.selectDataSource(CmkCEE);
128+
103129
cy.contains('Checkmk ' + CmkCEE).should('be.visible'); // Assert Cmk CEE datasource is used
104130
cy.inputLocatorById(inputFilterId).type('Service{enter}'); // Filter -> 'Service'
105131

106132
cy.inputLocatorById(inputServiceId).type('{enter}'); // Service -> 'Check_MK' (first entry)
107133
cy.contains('Check_MK').should('exist');
108134

135+
cy.inputLocatorById(inputFilterId).type('regex{enter}'); // Filter -> 'Hostname regex'
136+
cy.get('input[data-test-id="host_name_regex-filter-input"]').type('localhost_grafana[0-9]+{enter}');
137+
109138
cy.inputLocatorById(inputGraphId).click();
110139
cy.get('[class="scrollbar-view"]')
111140
.children()
@@ -135,6 +164,7 @@ describe('e2e tests', () => {
135164
});
136165

137166
it('RAM-used panel by service regex (multiple hosts)', {}, () => {
167+
cy.selectDataSource(CmkCEE);
138168
cy.contains('Checkmk ' + CmkCEE).should('be.visible'); // Assert Cmk CEE datasource is used
139169
cy.inputLocatorById(inputFilterId).type('Service regex{enter}'); // Filter -> 'Service'
140170
cy.contains('Service regex').should('exist');
@@ -155,14 +185,15 @@ describe('e2e tests', () => {
155185
});
156186

157187
it('RAM-used panel by host labels (multiple hosts, single metric)', {}, () => {
188+
cy.selectDataSource(CmkCEE);
158189
cy.contains('Checkmk ' + CmkCEE).should('be.visible'); // Assert Cmk CEE datasource is used
159190
cy.inputLocatorById(inputFilterId).type('Host labels{enter}'); // Filter -> 'Host labels'
160191
cy.contains('Host labels').should('exist');
161192

162-
cy.inputLocatorById('react-select-15-input').type('cmk/site:cm'); // Host labels -> 'cmk/site:cm' (one entry)
193+
cy.inputLocatorById(inputHostLabelId).type('cmk/site:cm'); // Host labels -> 'cmk/site:cm' (one entry)
163194
// TODO: should only contain a single lable, but shows all?
164-
cy.contains('cmk/site:cmk').should('exist');
165-
cy.contains('cmk/site:cmk').click();
195+
cy.contains(`cmk/site:${cmkSite}`).should('exist');
196+
cy.contains(`cmk/site:${cmkSite}`).click();
166197

167198
cy.inputLocatorById(inputGraphTypeId).click(); // Graph type -> 'Single metric'
168199
cy.contains('Single metric').click();
@@ -182,6 +213,7 @@ describe('e2e tests', () => {
182213
});
183214

184215
it('RAM-used panel by service regex and hostname regex', {}, () => {
216+
cy.selectDataSource(CmkCEE);
185217
cy.contains('Checkmk ' + CmkCEE).should('be.visible'); // Assert Cmk CEE datasource is used
186218
cy.inputLocatorById(inputFilterId).type('Service regex{enter}'); // Filter -> 'Service'
187219
cy.contains('Service regex').should('exist');
@@ -224,6 +256,7 @@ describe('e2e tests', () => {
224256
});
225257

226258
it('Uptime panel by hostname', {}, () => {
259+
cy.selectDataSource(CmkCEE);
227260
cy.contains('Checkmk ' + CmkCEE).should('be.visible'); // Assert Cmk CEE datasource is used
228261
cy.inputLocatorById(inputFilterId).type('Hostname{enter}'); // Filter -> 'Host name'
229262

@@ -250,6 +283,8 @@ describe('e2e tests', () => {
250283
});
251284
describe('CRE tests', () => {
252285
it('time-usage panel by service (single host)', {}, () => {
286+
cy.selectDataSource(CmkCRE);
287+
253288
cy.passOnException('ResizeObserver loop limit exceeded');
254289
cy.inputLocatorById(inputDatasourceId).type('Checkmk ' + CmkCRE + '{enter}');
255290
cy.contains('Checkmk ' + CmkCRE).should('be.visible');
@@ -282,6 +317,8 @@ describe('e2e tests', () => {
282317
cy.contains("Could not find 'cmk_cpu_time_by_phase'").should('be.visible'); // Assert previous graph input not visible
283318
});
284319
it('Used-RAM panel by service (single host)', {}, () => {
320+
cy.selectDataSource(CmkCRE);
321+
285322
cy.passOnException('ResizeObserver loop limit exceeded');
286323
cy.inputLocatorById(inputDatasourceId).type('Checkmk ' + CmkCRE + '{enter}');
287324
cy.contains('Checkmk ' + CmkCRE).should('be.visible');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const Selectors = {
2+
SetupForm: {
3+
name: 'input[id="basic-settings-name"]',
4+
url: '[data-test-id="checkmk-url"]',
5+
edition: 'input[id="checkmk-edition"]',
6+
username: '[data-test-id="checkmk-username"]',
7+
password: '[data-test-id="checkmk-password"]',
8+
version: '[id="checkmk-version"]',
9+
},
10+
AddDashboard: {
11+
filterFieldId: 'input_add_filter',
12+
hostLabelFieldId: 'input_host_label',
13+
},
14+
};
15+
16+
export default Selectors;

tests/cypress/support/commands.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import CheckMkSelectors from './checkmk_selectors';
2+
import GrafanaSelectors from './grafana_selectors';
3+
14
export {};
25

36
const panelContentSelector = '[class$="panel-content"]';
@@ -7,9 +10,9 @@ const plottedHoverSelectorOn = '[class="u-cursor-pt"]';
710

811
Cypress.Commands.add('loginGrafana', () => {
912
cy.visit('/login');
10-
cy.get('input[name="user"]').type(Cypress.env('grafanaUsername'));
11-
cy.get('input[name="password"]').type(Cypress.env('grafanaPassword'));
12-
cy.get('[aria-label="Login button"]').click();
13+
cy.get(GrafanaSelectors.Login.username_input).type(Cypress.env('grafanaUsername'));
14+
cy.get(GrafanaSelectors.Login.password_input).type(Cypress.env('grafanaPassword'));
15+
cy.get(GrafanaSelectors.Login.login_button).click();
1316
// wait until page after logged in is fully loaded
1417
cy.contains('Recently viewed dashboards').should('be.visible');
1518
});
@@ -21,23 +24,29 @@ Cypress.Commands.add('logoutGrafana', () => {
2124
Cypress.Commands.add('addNewPanel', () => {
2225
// add a new panel in a new dashboard
2326
cy.visit('/dashboard/new');
24-
cy.get('button[aria-label="Add new panel"]').click();
27+
cy.get(GrafanaSelectors.AddDashboard.add_new_panel_button).click();
28+
});
29+
30+
Cypress.Commands.add('selectDataSource', (edition: string) => {
31+
if (GrafanaSelectors.grafanaVersion >= 10) {
32+
cy.get(`${GrafanaSelectors.AddDashboard.datasources_list}`).contains('button', `Checkmk ${edition}`).click();
33+
}
2534
});
2635

2736
Cypress.Commands.add('addCmkDatasource', (cmkUser: string, cmkPass: string, edition: string) => {
2837
cy.visit('/datasources/new');
29-
cy.get('button[aria-label="Add new data source Checkmk"]').contains('Checkmk').click();
38+
cy.get(GrafanaSelectors.AddDataSource.select_datasource_button('Checkmk')).contains('Checkmk').click();
3039

31-
cy.get('input[id="basic-settings-name"]').type(' ' + edition);
32-
cy.get('[data-test-id="checkmk-url"]').type(Cypress.env('grafanaToCheckmkUrl'));
33-
cy.get('input[id="react-select-2-input"]').type(edition + '{enter}'); // TODO: introduce an id for the input selector
40+
cy.get(CheckMkSelectors.SetupForm.name).type(' ' + edition);
41+
cy.get(CheckMkSelectors.SetupForm.url).type(Cypress.env('grafanaToCheckmkUrl'));
42+
cy.get(CheckMkSelectors.SetupForm.edition).type(edition + '{enter}');
3443
cy.contains(edition).should('exist');
3544

36-
cy.get('[data-test-id="checkmk-username"]').type(cmkUser);
37-
cy.get('[data-test-id="checkmk-password"]').type(cmkPass);
38-
cy.get('[id="checkmk-version"]').type('<{enter}');
45+
cy.get(CheckMkSelectors.SetupForm.username).type(cmkUser);
46+
cy.get(CheckMkSelectors.SetupForm.password).type(cmkPass);
47+
cy.get(CheckMkSelectors.SetupForm.version).type('<{enter}');
3948

40-
cy.get('[aria-label="Data source settings page Save and Test button"]').click();
49+
cy.get(GrafanaSelectors.AddDataSource.save_and_test_button).click();
4150

4251
cy.get('[data-testid="data-testid Alert success"]').should('be.visible');
4352
cy.contains('Data source is working').should('be.visible');
@@ -144,6 +153,7 @@ declare global {
144153
assertLegendElement(text: string): Chainable<void>;
145154
inputLocatorById(id: string): Chainable<JQuery>;
146155
inputLocatorByDataTestId(dataTestId: string): Chainable<JQuery>;
156+
selectDataSource(edition: string): Chainable<JQuery>;
147157
}
148158
}
149159
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const grafanaVersion = 10;
2+
3+
const addDataSourceSaveAndTestButtonV9 = 'button[aria-label="Data source settings page Save and Test button"]';
4+
const addDataSourceSaveAndTestButtonV10 = `button[data-testid="data-testid Data source settings page Save and Test button"]`;
5+
6+
const addNewPanelButtonV9 = 'button[aria-label="Add new panel"]';
7+
const addNewPanelButtonV10 = 'button[data-testid="data-testid Create new panel button"]';
8+
9+
const Selectors = {
10+
grafanaVersion,
11+
Login: {
12+
username_input: 'input[name="user"]',
13+
password_input: 'input[name="password"]',
14+
login_button: 'button[aria-label="Login button"]',
15+
},
16+
17+
AddDataSource: {
18+
select_datasource_button: (name: string): string => `button[aria-label="${`Add new data source ${name}`}"]`,
19+
save_and_test_button: grafanaVersion >= 10 ? addDataSourceSaveAndTestButtonV10 : addDataSourceSaveAndTestButtonV9,
20+
},
21+
22+
AddDashboard: {
23+
add_new_panel_button: grafanaVersion >= 10 ? addNewPanelButtonV10 : addNewPanelButtonV9,
24+
datasources_list: 'div[data-testid="data-sources-list"]',
25+
},
26+
};
27+
28+
export default Selectors;

tests/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3'
22

33
services:
44
grafana:
5-
image: grafana/grafana-oss:9.5.3-ubuntu
5+
image: grafana/grafana-oss:latest
66
volumes:
77
- ../dist/:/var/lib/grafana/plugins/grafana-checkmk-datasource
88
environment:

tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"author": "",
1010
"license": "GPL-2.0-only",
1111
"devDependencies": {
12-
"cypress": "^12.11.0"
12+
"cypress": "13.3.3"
1313
}
1414
}

0 commit comments

Comments
 (0)