Skip to content

Fix flaky e2e test #7620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v3.34
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions cypress/e2e/console/devices/device-on-othercluster.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@ describe('End device on other cluster', () => {
ids: { application_id: applicationId },
}

const deviceId = 'device-all-components'

const ns = {
end_device: {
frequency_plan_id: 'EU_863_870_TTN',
lorawan_phy_version: 'PHY_V1_0_2_REV_A',
multicast: false,
supports_join: true,
lorawan_version: 'MAC_V1_0_2',
ids: {
device_id: deviceId,
dev_eui: '70B3D57ED8000019',
join_eui: '0000000000000000',
},
supports_class_c: false,
supports_class_b: false,
mac_settings: {
Expand Down Expand Up @@ -69,11 +62,6 @@ describe('End device on other cluster', () => {

const is = {
end_device: {
ids: {
dev_eui: '9000BEEF9000BEEF',
join_eui: '0000000000000000',
device_id: 'device-all-components',
},
network_server_address: 'tti.staging1.cloud.thethings.industries',
application_server_address: 'tti.staging1.cloud.thethings.industries',
join_server_address: 'tti.staging1.cloud.thethings.industries',
Expand All @@ -83,11 +71,15 @@ describe('End device on other cluster', () => {
},
}

let deviceId

before(() => {
cy.dropAndSeedDatabase()
cy.createUser(user)
cy.createApplication(application, user.ids.user_id)
cy.createMockDeviceAllComponents(applicationId, undefined, { ns, is })
cy.createMockDeviceAllComponents(applicationId, undefined, { ns, is }).then(body => {
deviceId = body.end_device.ids.device_id
})
})

beforeEach(() => {
Expand Down
15 changes: 8 additions & 7 deletions cypress/e2e/console/devices/device-overview.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ describe('Device overview', () => {
multicast: false,
supports_join: false,
lorawan_version: 'MAC_V1_0_2',
ids: {
device_id: 'device-all-components',
dev_eui: '70B3D57ED8000019',
},
session: {
keys: {
f_nwk_s_int_key: {
Expand All @@ -52,13 +48,18 @@ describe('Device overview', () => {
},
},
}
const endDeviceId = ns.end_device.ids.device_id

let endDeviceId
let endDeviceDevEui

before(() => {
cy.dropAndSeedDatabase()
cy.createUser(user)
cy.createApplication(application, userId)
cy.createMockDeviceAllComponents(appId, undefined, { ns })
cy.createMockDeviceAllComponents(appId, undefined, { ns }).then(body => {
endDeviceId = body.end_device.ids.device_id
endDeviceDevEui = body.end_device.ids.dev_eui
})
})

beforeEach(() => {
Expand Down Expand Up @@ -86,7 +87,7 @@ describe('Device overview', () => {
application_ids: {
application_id: appId,
},
dev_eui: '70B3D57ED8000019',
dev_eui: endDeviceDevEui,
dev_addr: '270000FC',
},
created_at: '2021-07-06T21:32:48.499001538Z',
Expand Down
14 changes: 7 additions & 7 deletions cypress/e2e/console/devices/edit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ describe('Device general settings', () => {
multicast: false,
supports_join: false,
lorawan_version: 'MAC_V1_0_2',
ids: {
device_id: 'device-all-components',
dev_eui: '70B3D57ED8000019',
},
session: {
keys: {
f_nwk_s_int_key: {
Expand All @@ -54,13 +50,17 @@ describe('Device general settings', () => {
},
},
}
const endDeviceId = ns.end_device.ids.device_id
let endDeviceId
let endDeviceDevEui

before(() => {
cy.dropAndSeedDatabase()
cy.createUser(user)
cy.createApplication(application, userId)
cy.createMockDeviceAllComponents(appId, undefined, { ns })
cy.createMockDeviceAllComponents(appId, undefined, { ns }).then(body => {
endDeviceId = body.end_device.ids.device_id
endDeviceDevEui = body.end_device.ids.dev_eui
})
})

beforeEach(() => {
Expand All @@ -82,7 +82,7 @@ describe('Device general settings', () => {
cy.findByLabelText('DevEUI')
.should('be.disabled')
.and('have.attr', 'value')
.and('eq', ns.end_device.ids.dev_eui)
.and('eq', endDeviceDevEui)

cy.fixture('console/devices/device.is.json').then(endDevice => {
cy.findByLabelText('End device name')
Expand Down
19 changes: 10 additions & 9 deletions cypress/e2e/console/devices/unclaim.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ describe('Device un-claiming', () => {
multicast: false,
supports_join: false,
lorawan_version: 'MAC_V1_0_2',
ids: {
device_id: 'device-all-components',
dev_eui: '70B3D57ED8000019',
},
session: {
keys: {
f_nwk_s_int_key: {
Expand All @@ -52,13 +48,19 @@ describe('Device un-claiming', () => {
},
},
}
const endDeviceId = ns.end_device.ids.device_id
let endDeviceId
let endDeviceDevEui
let endDeviceJoinEui

before(() => {
cy.dropAndSeedDatabase()
cy.createUser(user)
cy.createApplication(application, userId)
cy.createMockDeviceAllComponents(appId, undefined, { ns })
cy.createMockDeviceAllComponents(appId, undefined, { ns }).then(body => {
endDeviceId = body.end_device.ids.device_id
endDeviceDevEui = body.end_device.ids.dev_eui
endDeviceJoinEui = body.end_device.ids.join_eui
})
})

beforeEach(() => {
Expand Down Expand Up @@ -92,9 +94,8 @@ describe('Device un-claiming', () => {
const params = new URLSearchParams(new URL(url).search)
const hexToBase64 = hex =>
btoa(String.fromCharCode(...hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))))

expect(params.get('dev_eui')).to.equal(hexToBase64(ns.end_device.ids.dev_eui))
expect(params.get('join_eui')).to.equal(hexToBase64('0000000000000000'))
expect(params.get('dev_eui')).to.equal(hexToBase64(endDeviceDevEui))
expect(params.get('join_eui')).to.equal(hexToBase64(endDeviceJoinEui))
})

cy.findByTestId('error-notification').should('not.exist')
Expand Down
10 changes: 0 additions & 10 deletions cypress/e2e/console/shared/payload-formatters/edit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ describe('Payload formatters', () => {
fw_version: 'quickstart',
band_id: 'EU_863_870',
},
ids: {
device_id: 'device-all-components',
dev_eui: '70B3D57ED8000013',
join_eui: '0000000000000006',
},
supports_class_c: false,
supports_class_b: false,
mac_settings: {
Expand Down Expand Up @@ -75,11 +70,6 @@ describe('Payload formatters', () => {

const is = {
end_device: {
ids: {
dev_eui: '70B3D57ED8000013',
join_eui: '0000000000000006',
device_id: 'device-all-components',
},
network_server_address: window.location.hostname,
application_server_address: window.location.hostname,
join_server_address: window.location.hostname,
Expand Down
11 changes: 5 additions & 6 deletions cypress/e2e/smoke/devices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@ const checkCollapsingFields = defineSmokeTest('check all end device sub pages',
const application = {
ids: { application_id: applicationId },
}
const deviceId = 'device-all-components'
const ns = {
end_device: {
frequency_plan_id: 'EU_863_870_TTN',
lorawan_phy_version: 'PHY_V1_0_2_REV_B',
multicast: false,
supports_join: false,
lorawan_version: 'MAC_V1_0_2',
ids: {
device_id: 'device-all-components',
dev_eui: '70B3D57ED8000019',
},
session: {
keys: {
f_nwk_s_int_key: {
Expand All @@ -63,6 +58,8 @@ const checkCollapsingFields = defineSmokeTest('check all end device sub pages',
cy.createUser(user)
cy.createApplication(application, user.ids.user_id)
cy.createMockDeviceAllComponents(applicationId, undefined, { ns })
.its('end_device.ids.device_id')
.as('deviceId')
cy.loginConsole({ user_id: user.ids.user_id, password: user.password })
cy.visit(Cypress.config('consoleRootPath'))

Expand All @@ -71,7 +68,9 @@ const checkCollapsingFields = defineSmokeTest('check all end device sub pages',
cy.get('#sidebar').within(() => {
cy.findByRole('link', { name: /End devices/ }).click()
})
cy.findByRole('cell', { name: `Test Device Name ${deviceId}` }).click()
cy.get('@deviceId').then(deviceId => {
cy.findByRole('cell', { name: `Test Device Name ${deviceId}` }).click()
})

cy.get('#stage').within(() => {
cy.findByRole('button', { name: 'Live data' }).click()
Expand Down
29 changes: 23 additions & 6 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { noop, merge } from 'lodash'

import stringToHash from '../../pkg/webui/lib/string-to-hash'

import { generateHexValue } from './utils'

before(() => {
cy.readFile('.env/admin_api_key.txt').then(adminKey => {
Cypress.config('adminApiKey', adminKey)
Expand Down Expand Up @@ -319,16 +321,25 @@ Cypress.Commands.add(
(
applicationId,
fixture = 'console/devices/device.*.json',
overwrites = { ns: {}, as: {}, js: {}, is: {} },
overwrites = {},
injectHost = true,
) => {
const randomSuffix = Cypress._.random(0, 1e6)
const deviceIds = {
device_id: `device-${Date.now()}-${randomSuffix}`,
dev_eui: generateHexValue(16).toUpperCase(),
join_eui: generateHexValue(16).toUpperCase(),
}
const mergedOverwrites = Cypress._.merge({ ns: {}, as: {}, js: {}, is: {} }, overwrites)
const { ns, as, js, is } = mergedOverwrites
const baseUrl = Cypress.config('baseUrl')
const adminApiKey = Cypress.config('adminApiKey')
const interpolateFixture = (fixtureString, component) => fixtureString.replace('*', component)
const headers = {
Authorization: `Bearer ${adminApiKey}`,
}
cy.fixture(interpolateFixture(fixture, 'is')).then(body => {
body.end_device.ids = deviceIds
if (injectHost && body && 'end_device' in body) {
if ('network_server_address' in body.end_device) {
body.end_device.network_server_address = window.location.hostname
Expand All @@ -343,27 +354,30 @@ Cypress.Commands.add(
cy.request({
method: 'POST',
url: `${baseUrl}/api/v3/applications/${applicationId}/devices`,
body: { ...body, ...overwrites.is },
body: Cypress._.merge({}, body, is),
headers,
})
})
cy.fixture(interpolateFixture(fixture, 'ns')).then(body => {
body.end_device.ids = deviceIds
cy.request({
method: 'PUT',
url: `${baseUrl}/api/v3/ns/applications/${applicationId}/devices/${body.end_device.ids.device_id}`,
body: { ...body, ...overwrites.ns },
body: Cypress._.merge({}, body, ns),
headers,
})
})
cy.fixture(interpolateFixture(fixture, 'as')).then(body => {
body.end_device.ids = deviceIds
cy.request({
method: 'PUT',
url: `${baseUrl}/api/v3/as/applications/${applicationId}/devices/${body.end_device.ids.device_id}`,
body: { ...body, ...overwrites.as },
body: Cypress._.merge({}, body, as),
headers,
})
})
cy.fixture(interpolateFixture(fixture, 'js')).then(body => {
body.end_device.ids = deviceIds
if (injectHost && body && 'end_device' in body) {
if ('network_server_address' in body.end_device) {
body.end_device.network_server_address = window.location.hostname
Expand All @@ -375,11 +389,14 @@ Cypress.Commands.add(
cy.request({
method: 'PUT',
url: `${baseUrl}/api/v3/js/applications/${applicationId}/devices/${body.end_device.ids.device_id}`,
body: { ...body, ...overwrites.js },
body: Cypress._.merge({}, body, js),
headers,
})
})
return cy.fixture(interpolateFixture(fixture, 'is'))
return cy.fixture(interpolateFixture(fixture, 'is')).then(body => {
body.end_device.ids = deviceIds
return body
})
},
)

Expand Down
Loading