From 78ba034a6998d128dcb3443034cb23cff4e50613 Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Mon, 28 Aug 2023 12:26:41 +0200 Subject: [PATCH] [Logs onboarding] e2e tests - entry points (#164561) Relates to https://github.com/elastic/kibana/issues/164022. --- .../e2e/cypress/e2e/home.cy.ts | 19 ++++++++- .../observability/cypress/cypress.config.ts | 14 +++++++ .../cypress/e2e/navigation.cy.ts | 35 +++++----------- .../e2e/observability_onboarding/home.cy.ts | 26 ++++++++++++ .../observability/cypress/support/commands.ts | 41 ++++++++++++++++--- .../observability/cypress/support/types.d.ts | 1 + 6 files changed, 104 insertions(+), 32 deletions(-) create mode 100644 x-pack/test_serverless/functional/test_suites/observability/cypress/e2e/observability_onboarding/home.cy.ts diff --git a/x-pack/plugins/observability_onboarding/e2e/cypress/e2e/home.cy.ts b/x-pack/plugins/observability_onboarding/e2e/cypress/e2e/home.cy.ts index 8f65ec2e721f5..71aa6a0eb09e6 100644 --- a/x-pack/plugins/observability_onboarding/e2e/cypress/e2e/home.cy.ts +++ b/x-pack/plugins/observability_onboarding/e2e/cypress/e2e/home.cy.ts @@ -10,7 +10,24 @@ describe('[Observability onboarding] Landing page', () => { cy.loginAsElastic(); }); - it('shows landing page', () => { + describe('Entry point', () => { + it('when clicking on the logs card the user is navigated to the observability onboarding page', () => { + cy.getByTestSubj('guideButtonRedirect').click(); + cy.getByTestSubj('onboarding--observability--logs').click(); + + cy.url().should('include', '/app/observabilityOnboarding'); + }); + + it('when clicking on observability overview callout the user is navigated to the observability onboarding page', () => { + cy.visitKibana('/app/observability'); + cy.getByTestSubj('observability-onboarding-callout').should('exist'); + cy.getByTestSubj('o11yObservabilityOnboardingGetStartedButton').click(); + + cy.url().should('include', '/app/observabilityOnboarding'); + }); + }); + + it('when user navigates to observability onboarding landing page is showed', () => { cy.visitKibana('/app/observabilityOnboarding'); cy.contains('Get started with Observability'); }); diff --git a/x-pack/test_serverless/functional/test_suites/observability/cypress/cypress.config.ts b/x-pack/test_serverless/functional/test_suites/observability/cypress/cypress.config.ts index f078275aab2eb..52eaff1a67792 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/cypress/cypress.config.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/cypress/cypress.config.ts @@ -6,6 +6,15 @@ */ import { defineCypressConfig } from '@kbn/cypress-config'; +import { kbnTestConfig } from '@kbn/test'; + +import Url from 'url'; + +const kibanaUrlWithoutAuth = Url.format({ + protocol: kbnTestConfig.getUrlParts().protocol, + hostname: kbnTestConfig.getUrlParts().hostname, + port: kbnTestConfig.getUrlParts().port, +}); export default defineCypressConfig({ fileServerFolder: './cypress', @@ -30,4 +39,9 @@ export default defineCypressConfig({ supportFile: './support/e2e.ts', specPattern: './e2e/**/*.cy.ts', }, + env: { + username: kbnTestConfig.getUrlParts().username, + password: kbnTestConfig.getUrlParts().password, + kibanaUrlWithoutAuth, + }, }); diff --git a/x-pack/test_serverless/functional/test_suites/observability/cypress/e2e/navigation.cy.ts b/x-pack/test_serverless/functional/test_suites/observability/cypress/e2e/navigation.cy.ts index df1bea1e56e85..84abae3258cff 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/cypress/e2e/navigation.cy.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/cypress/e2e/navigation.cy.ts @@ -6,12 +6,11 @@ */ describe('Serverless', () => { - it('Should login', () => { + beforeEach(() => { cy.loginAsElasticUser(); }); it('contains the side navigation for observabilitity serverless', () => { - cy.loginAsElasticUser(); cy.contains('Discover'); cy.contains('Dashboards'); cy.contains('Alerts'); @@ -23,8 +22,6 @@ describe('Serverless', () => { }); it('navigates to discover-dashboard-viz links', () => { - cy.loginAsElasticUser(); - cy.contains('Discover').click(); cy.url().should('include', '/app/discover'); @@ -36,8 +33,6 @@ describe('Serverless', () => { }); it('navigates to alerts links', () => { - cy.loginAsElasticUser(); - cy.contains('Alerts').click(); cy.url().should('include', '/observability/alerts'); @@ -49,8 +44,6 @@ describe('Serverless', () => { }); it('navigates to apm links', () => { - cy.loginAsElasticUser(); - cy.contains('Applications').click(); cy.contains('Services').click(); cy.url().should('include', '/apm/services'); @@ -63,15 +56,11 @@ describe('Serverless', () => { }); it('navigates to get started links', () => { - cy.loginAsElasticUser(); - cy.contains('Add data').click(); cy.url().should('include', '/app/observabilityOnboarding'); }); it('navigates to AIOps links', () => { - cy.loginAsElasticUser(); - cy.contains('AIOps').click(); cy.contains('Anomaly detection').click(); cy.url().should('include', '/app/ml/jobs'); @@ -87,8 +76,6 @@ describe('Serverless', () => { }); it('navigates to project settings', () => { - cy.loginAsElasticUser(); - cy.contains('Project settings').click(); cy.contains('Management').click(); cy.url().should('include', '/app/management'); @@ -101,22 +88,21 @@ describe('Serverless', () => { }); it('sets service nav item as active', () => { - cy.loginAsElasticUser('/app/apm/service-groups'); - + cy.visitKibana('/app/apm/service-groups'); cy.getByTestSubj('nav-item-id-apm').should('have.class', 'euiSideNavItemButton-isOpen'); cy.getByTestSubj('nav-item-id-apm:services').should( 'have.class', 'euiSideNavItemButton-isSelected' ); - cy.loginAsElasticUser('/app/apm/service-maps'); + cy.visitKibana('/app/apm/service-maps'); cy.getByTestSubj('nav-item-id-apm').should('have.class', 'euiSideNavItemButton-isOpen'); cy.getByTestSubj('nav-item-id-apm:services').should( 'have.class', 'euiSideNavItemButton-isSelected' ); - cy.loginAsElasticUser('/app/apm/mobile-services/foo'); + cy.visitKibana('/app/apm/mobile-services/foo'); cy.getByTestSubj('nav-item-id-apm').should('have.class', 'euiSideNavItemButton-isOpen'); cy.getByTestSubj('nav-item-id-apm:services').should( 'have.class', @@ -125,15 +111,14 @@ describe('Serverless', () => { }); it('sets dependencies nav item as active', () => { - cy.loginAsElasticUser('/app/apm/dependencies/inventory'); - + cy.visitKibana('/app/apm/dependencies/inventory'); cy.getByTestSubj('nav-item-id-apm').should('have.class', 'euiSideNavItemButton-isOpen'); cy.getByTestSubj('nav-item-id-apm:dependencies').should( 'have.class', 'euiSideNavItemButton-isSelected' ); - cy.loginAsElasticUser('/app/apm/dependencies/operations?dependencyName=foo'); + cy.visitKibana('/app/apm/dependencies/operations?dependencyName=foo'); cy.getByTestSubj('nav-item-id-apm').should('have.class', 'euiSideNavItemButton-isOpen'); cy.getByTestSubj('nav-item-id-apm:dependencies').should( 'have.class', @@ -142,7 +127,7 @@ describe('Serverless', () => { }); it('sets traces nav item as active', () => { - cy.loginAsElasticUser('/app/apm/traces/explorer/waterfall'); + cy.visitKibana('/app/apm/traces/explorer/waterfall'); cy.getByTestSubj('nav-item-id-apm').should('have.class', 'euiSideNavItemButton-isOpen'); cy.getByTestSubj('nav-item-id-apm:traces').should( @@ -150,7 +135,7 @@ describe('Serverless', () => { 'euiSideNavItemButton-isSelected' ); - cy.loginAsElasticUser('/app/apm/traces/explorer/critical_path'); + cy.visitKibana('/app/apm/traces/explorer/critical_path'); cy.getByTestSubj('nav-item-id-apm').should('have.class', 'euiSideNavItemButton-isOpen'); cy.getByTestSubj('nav-item-id-apm:traces').should( 'have.class', @@ -159,7 +144,7 @@ describe('Serverless', () => { }); it('sets AIOps nav item as active', () => { - cy.loginAsElasticUser('app/ml/aiops/explain_log_rate_spikes'); + cy.visitKibana('/app/ml/aiops/explain_log_rate_spikes'); cy.getByTestSubj('nav-item-id-aiops').should('have.class', 'euiSideNavItemButton-isOpen'); cy.getByTestSubj('nav-item-id-ml:logRateAnalysis').should( @@ -167,7 +152,7 @@ describe('Serverless', () => { 'euiSideNavItemButton-isSelected' ); - cy.loginAsElasticUser('app/ml/aiops/change_point_detection'); + cy.visitKibana('/app/ml/aiops/change_point_detection'); cy.getByTestSubj('nav-item-id-aiops').should('have.class', 'euiSideNavItemButton-isOpen'); cy.getByTestSubj('nav-item-id-ml:changePointDetections').should( 'have.class', diff --git a/x-pack/test_serverless/functional/test_suites/observability/cypress/e2e/observability_onboarding/home.cy.ts b/x-pack/test_serverless/functional/test_suites/observability/cypress/e2e/observability_onboarding/home.cy.ts new file mode 100644 index 0000000000000..7e74c75b62ebc --- /dev/null +++ b/x-pack/test_serverless/functional/test_suites/observability/cypress/e2e/observability_onboarding/home.cy.ts @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +describe('[Serverless Observability onboarding] Landing page', () => { + beforeEach(() => { + cy.loginAsElasticUser(); + }); + + it('when user navigates to observability onboarding landing page is showed', () => { + cy.visitKibana('/app/observabilityOnboarding'); + cy.contains('Get started with Observability'); + }); + + describe('Entry point', () => { + it('when clicking on Add data the user is navigated to the observability onboarding page', () => { + cy.contains('Add data').click(); + cy.url().should('include', '/app/observabilityOnboarding'); + }); + }); +}); + +export {}; diff --git a/x-pack/test_serverless/functional/test_suites/observability/cypress/support/commands.ts b/x-pack/test_serverless/functional/test_suites/observability/cypress/support/commands.ts index f9cea31215176..715e5c9df22fc 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/cypress/support/commands.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/cypress/support/commands.ts @@ -4,18 +4,47 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import 'cypress-real-events/support'; import 'cypress-axe'; +import 'cypress-real-events/support'; +import URL from 'url'; -Cypress.Commands.add('loginAsElasticUser', (path?: string) => { - cy.visit(path ?? '/', { - auth: { - username: 'elastic', - password: 'changeme', +Cypress.Commands.add('loginAsElasticUser', () => { + const username = Cypress.env('username'); + const password = Cypress.env('password'); + const kibanaUrlWithoutAuth = Cypress.env('kibanaUrlWithoutAuth'); + cy.log(`Logging in as ${username} on ${kibanaUrlWithoutAuth}`); + cy.visit('/'); + cy.request({ + log: true, + method: 'POST', + url: `${kibanaUrlWithoutAuth}/internal/security/login`, + body: { + providerType: 'basic', + providerName: 'basic', + currentURL: `${kibanaUrlWithoutAuth}/login`, + params: { username, password }, + }, + headers: { + 'kbn-xsrf': 'e2e_test', + 'x-elastic-internal-origin': 'kibana', }, }); + cy.visit('/'); }); Cypress.Commands.add('getByTestSubj', (selector: string) => { return cy.get(`[data-test-subj*="${selector}"]`); }); + +Cypress.Commands.add('visitKibana', (url: string, rangeFrom?: string, rangeTo?: string) => { + const urlPath = URL.format({ + pathname: url, + query: { rangeFrom, rangeTo }, + }); + + cy.visit(urlPath); + cy.getByTestSubj('kbnLoadingMessage').should('exist'); + cy.getByTestSubj('kbnLoadingMessage').should('not.exist', { + timeout: 50000, + }); +}); diff --git a/x-pack/test_serverless/functional/test_suites/observability/cypress/support/types.d.ts b/x-pack/test_serverless/functional/test_suites/observability/cypress/support/types.d.ts index ae802c601d193..7b11b4916742c 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/cypress/support/types.d.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/cypress/support/types.d.ts @@ -9,5 +9,6 @@ declare namespace Cypress { interface Chainable { loginAsElasticUser(path?: string): Cypress.Chainable>; getByTestSubj(selector: string): Chainable>; + visitKibana(url: string, rangeFrom?: string, rangeTo?: string): void; } }