From 5e9ec21f2a2d5013052db885c33e23a4361a9edb Mon Sep 17 00:00:00 2001 From: Sahar Kargar <93485533+SaharKargar@users.noreply.github.com> Date: Sat, 6 Aug 2022 18:59:46 +0430 Subject: [PATCH] Fix enabled clusters test file (#636) * fix enabled clusters test file * adding ci for cypress against matter data * updating cypress.json --- .github/workflows/mattercypress.yml | 34 ++++++++++ cypress.json | 4 +- .../attribute_validations/bitmap.spec.js | 2 +- .../attribute_validations/bitmap8.spec.js | 32 --------- .../attributes/check-validation.spec.js | 51 -------------- .../check_summary/enabled-clusters.spec.js | 32 +++++---- package.json | 3 + src-script/zap-uitestmatter.js | 66 +++++++++++++++++++ 8 files changed, 122 insertions(+), 102 deletions(-) create mode 100644 .github/workflows/mattercypress.yml delete mode 100644 cypress/integration/attribute_validations/bitmap8.spec.js delete mode 100644 cypress/integration/attributes/check-validation.spec.js create mode 100644 src-script/zap-uitestmatter.js diff --git a/.github/workflows/mattercypress.yml b/.github/workflows/mattercypress.yml new file mode 100644 index 00000000..9e5e45b4 --- /dev/null +++ b/.github/workflows/mattercypress.yml @@ -0,0 +1,34 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Cypress UI tests against matter data + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + node-version: [16.x] + os: [ubuntu-latest, ubuntu-18.04] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: sudo ./src-script/install-packages-ubuntu + - run: sudo apt-get install --fix-missing xvfb + - run: npm ci + - run: npm run version-stamp + - run: npm rebuild canvas --update-binary + - run: npm rebuild libxmljs --update-binary + - run: npm run build-spa + - run: xvfb-run -a npm run test:e2e-matter-ci diff --git a/cypress.json b/cypress.json index d0ec2d77..156e726e 100644 --- a/cypress.json +++ b/cypress.json @@ -6,6 +6,8 @@ "**/file_open.spec.js", "**/*.test.js", "**/*.xml", - "**/*.zap" + "**/*.zap", + "**/custom_xml.spec.js", + "**/check-cluster-attributes-singleton-in-zigbee-mode.spec.js" ] } diff --git a/cypress/integration/attribute_validations/bitmap.spec.js b/cypress/integration/attribute_validations/bitmap.spec.js index a9ea03a8..833632e9 100644 --- a/cypress/integration/attribute_validations/bitmap.spec.js +++ b/cypress/integration/attribute_validations/bitmap.spec.js @@ -22,7 +22,7 @@ describe('Testing BITMAP type validation', () => { cy.fixture('data').then((data) => { if (data.endpoint1 === 'Matter Bridge (0x000E)') { cy.get( - '#qvs_61 > :nth-child(6) > :nth-child(2) > .q-mt-xs > .q-toggle__inner' + '[data-cy=Attributes] > .q-table__middle > .q-table > .q-virtual-scroll__content > :nth-child(6) > :nth-child(2) > .q-mt-xs > .q-toggle__inner' ).click({ force: true }) } cy.get( diff --git a/cypress/integration/attribute_validations/bitmap8.spec.js b/cypress/integration/attribute_validations/bitmap8.spec.js deleted file mode 100644 index 441d7868..00000000 --- a/cypress/integration/attribute_validations/bitmap8.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/// <reference types="cypress" /> - -Cypress.on('uncaught:exception', (err, runnable) => { - // returning false here prevents Cypress from - // failing the test - return false -}) - -describe('Testing BITMAP8 type validation', () => { - it('create a new endpoint and click on configure to open attributes of endpoint', () => { - cy.fixture('baseurl').then((data) => { - cy.visit(data.baseurl) - }) - cy.gotoAttributePage('Billing Unit (0x0203)', 'General') - }) - it( - 'getting an attribute with BITMAP8 type and change default amount', - { retries: { runMode: 2, openMode: 2 } }, - () => { - cy.get( - ':nth-child(16) > [style="min-width: 180px;"] > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > input' - ) - .clear({ force: true }) - .type('test', { force: true }) - } - ) - it('check if validation works properly', () => { - cy.get( - ':nth-child(16) > [style="min-width: 180px;"] > .q-field > .q-field__inner > .q-field__bottom > .q-field__messages > div' - ).should('exist') - }) -}) diff --git a/cypress/integration/attributes/check-validation.spec.js b/cypress/integration/attributes/check-validation.spec.js deleted file mode 100644 index 62918354..00000000 --- a/cypress/integration/attributes/check-validation.spec.js +++ /dev/null @@ -1,51 +0,0 @@ -/// <reference types="cypress" /> - -Cypress.on('uncaught:exception', (err, runnable) => { - // returning false here prevents Cypress from - // failing the test - return false -}) - -describe('Testing attribute validation', () => { - it('create a new endpoint and click on configure to open attributes of endpoint', () => { - cy.fixture('baseurl').then((data) => { - cy.visit(data.baseurl) - }) - cy.fixture('data').then((data) => { - cy.gotoAttributePage(data.endpoint1, data.cluster1) - }) - }) - it( - 'change default input to a wrong amount', - { retries: { runMode: 2, openMode: 2 } }, - () => { - cy.fixture('data').then((data) => { - cy.get( - ':nth-child(1) > [style="min-width: 180px;"] > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > input' - ) - .clear({ force: true }) - .type(data.outOfRangeAmount1, { force: true }) - .then(() => { - cy.get('.table_body:first > [style="min-width: 180px;"]').should( - 'contain', - 'Out of range' - ) - }) - }) - } - ) - it( - 'change default input to a correct amount', - { retries: { runMode: 2, openMode: 2 } }, - () => { - cy.get( - ':nth-child(1) > [style="min-width: 180px;"] > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > input' - ) - .clear({ force: true }) - .type('111', { force: true }) - cy.get( - '[style="min-width: 180px;"] > .q-field > .q-field__inner > .q-field__bottom > .q-field__messages > div' - ).should('not.exist') - } - ) -}) diff --git a/cypress/integration/check_summary/enabled-clusters.spec.js b/cypress/integration/check_summary/enabled-clusters.spec.js index bb5129a6..9f692076 100644 --- a/cypress/integration/check_summary/enabled-clusters.spec.js +++ b/cypress/integration/check_summary/enabled-clusters.spec.js @@ -8,7 +8,7 @@ Cypress.on('uncaught:exception', (err, runnable) => { describe('Testing enabled clusters amount', () => { it( - 'create a new endpoint and enable a clusters', + 'create a new endpoint and get amount of enabled clusters', { retries: { runMode: 2, openMode: 2 } }, () => { cy.fixture('baseurl').then((data) => { @@ -21,22 +21,19 @@ describe('Testing enabled clusters amount', () => { const num1 = parseFloat($div.text()) cy.fixture('data').then((data) => { cy.get('.q-page-container > div') - .children() - .should('contain', data.cluster1) - }) - cy.get('div').contains('General').click({ force: true }) - cy.get('div') .children() - .contains('Server') - .its('length') - .then((res) => { - if (res > 0) { - cy.get('div').children().contains('Not Enabled').first().click() - cy.get('.q-virtual-scroll__content > :nth-child(3)') - .contains('Server') - .click() - } - }) + .should('contain', data.cluster1) + }) + cy.get('div').contains('General').click({force: true}) + cy.get('div').children().contains('Server').its('length').then(res=>{ + if(res > 0){ + cy.get('div').children().contains('Not Enabled').first().click() + cy.get('.q-virtual-scroll__content > :nth-child(3)') + .contains('Server') + .click() + } + }); + }) } ) @@ -50,6 +47,7 @@ describe('Testing enabled clusters amount', () => { expect(num2).to.eq(Number(data.availableClusters1)) }) }) + } ) -}) +}) \ No newline at end of file diff --git a/package.json b/package.json index aa231b98..84908ab4 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,8 @@ "test:unit:watchAll": "jest --watchAll", "test:e2e": "node src-script/zap-uitest.js open", "test:e2e-ci": "node src-script/zap-uitest.js run", + "test:e2e-matter": "node src-script/zap-uitestmatter.js open", + "test:e2e-matter-ci": "node src-script/zap-uitestmatter.js run", "report": "node src-script/zap-combine-reports.js", "postinstall": "electron-builder install-app-deps && husky install && npm rebuild canvas --update-binary && npm run version-stamp", "buildAndPack:win": "npm run build && npm run pack:win", @@ -59,6 +61,7 @@ "zaphelp": "node src-script/zap-start.js --help", "zap-dotdot": "node src-script/zap-start.js --logToStdout --zcl ./zcl-builtin/dotdot/library.xml", "zap-devserver": "node src-script/zap-start.js server --allowCors --logToStdout --gen ./test/gen-template/zigbee/gen-templates.json --reuseZapInstance", + "matterzap-devserver": "node src-script/zap-start.js server --allowCors ---logToStdout --zcl ./zcl-builtin/matter/zcl.json --gen ./test/resource/meta/gen-test.json --reuseZapInstance", "server": "node src-script/zap-start.js server --logToStdout --zcl ./zcl-builtin/silabs/zcl.json --zcl ./zcl-builtin/matter/zcl.json --gen ./test/gen-template/zigbee/gen-templates.json --reuseZapInstance", "stop": "node src-script/zap-start.js stop --reuseZapInstance", "status": "node src-script/zap-start.js status --reuseZapInstance", diff --git a/src-script/zap-uitestmatter.js b/src-script/zap-uitestmatter.js new file mode 100644 index 00000000..020397c5 --- /dev/null +++ b/src-script/zap-uitestmatter.js @@ -0,0 +1,66 @@ +#!/usr/bin/env node +/** + * + * Copyright (c) 2020 Silicon Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + const scriptUtil = require('./script-util.js') + + let cypressMode = 'run' + + if (process.argv.length > 2) { + cypressMode = process.argv[2] + } + + if (cypressMode == '-?') { + console.log(`Usage: zap-uitest.js [ MODE | -? ] + + This program executes the Cypress unit tests. + Valid modes: + run - [default] Executes all the Cypress tests in the headless mode. You might need to run via xvfb-run in a headless environment. + open - Executes Cypress UI for manual run of the tests.`) + process.exit(0) + } + + let returnCode = 0 + let svr = scriptUtil.executeCmd(null, 'npm', ['run', 'matterzap-devserver']) + + let cyp = scriptUtil.executeCmd(null, 'npx', [ + 'start-test', + 'quasar dev', + 'http-get://localhost:8080', + `npx cypress ${cypressMode} --config fixturesFolder=cypress/matterFixtures`, + ]) + + cyp + .then(() => { + returnCode = 0 + scriptUtil.executeCmd(null, 'npm', ['run', 'stop']) + }) + .catch(() => { + returnCode = 1 + scriptUtil.executeCmd(null, 'npm', ['run', 'stop']) + }) + + svr.then(() => { + if (returnCode == 0) { + console.log('😎 All done: Cypress tests passed and server shut down.') + process.exit(0) + } else { + console.log('⛔ Error: Cypress tests failed, server shut down.') + process.exit(returnCode) + } + }) + \ No newline at end of file -- GitLab