11import '../support/api_commands' ;
2+ import CheckmkSelectors from '../support/checkmk_selectors' ;
23import '../support/commands' ;
34
45describe ( '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' ) ;
0 commit comments