quick-wolf-87390
05/13/2022, 9:42 AMgray-kilobyte-89541
05/13/2022, 11:12 AMhallowed-barista-46832
05/13/2022, 12:00 PMmammoth-fall-22117
05/13/2022, 2:11 PMbitter-apple-86316
05/13/2022, 2:29 PMbitter-apple-86316
05/13/2022, 2:29 PMgray-kilobyte-89541
05/13/2022, 2:33 PMhallowed-barista-46832
05/13/2022, 3:34 PMcareful-solstice-12804
05/13/2022, 7:34 PMbroad-potato-69393
05/13/2022, 7:38 PMfast-forest-85580
05/14/2022, 8:40 PMcy.get('#user-name-label').should('have.text', 'Your username')
Now let's say I'm using a translation library like Vue I18n and I don't want to assert the hard-coded text Your username
but the translated content which is contained, for example, in a messages.json
translation file:
json
{
"usernameLabel": "This is your username"
}
Does Cypress provide some feature which allows to read the value of the usernameLabel
key for an assertion?adorable-smartphone-87280
05/14/2022, 9:28 PMpowerful-orange-86819
05/15/2022, 2:24 PMwonderful-match-15836
05/15/2022, 10:31 PMimport { defaultMessages } from `someplace/that/exports/the/messages`
cy.contains('label', defaultMessages.usernameLabel)
// ^ this replaces the .get() + the .should() in your example
// just because I like how short contains() is for selector + text assertions
That defaultMessages
is basically just the parsed JSON that you've already created.
Here's an example of how we do that export in Cypress but really whatever way you want to import and set this up for your tests should be fine: https://github.com/cypress-io/cypress/blob/10.0-release/packages/frontend-shared/src/locales/i18n.ts#L15fast-forest-85580
05/16/2022, 8:14 AMelegant-author-50450
05/16/2022, 11:54 AMuser
05/16/2022, 11:58 AMadventurous-dream-20049
05/17/2022, 8:27 PMadventurous-rose-66394
05/17/2022, 11:43 PMpowerful-orange-86819
05/18/2022, 8:11 AMcreamy-minister-50636
05/18/2022, 12:55 PMcolossal-car-90252
05/18/2022, 2:57 PMcalm-hydrogen-37718
05/18/2022, 3:41 PMadventurous-dream-20049
05/18/2022, 4:47 PMadventurous-dream-20049
05/18/2022, 4:48 PMsilly-dentist-68907
05/18/2022, 4:49 PMcalm-hydrogen-37718
05/18/2022, 5:03 PMimportant-bird-21355
05/18/2022, 7:25 PMproject
option to get around the fact that it's cloned inside the subfolder, but it didn't seem to work.
- uses: actions/checkout@v3
with:
repository: 'libra/gjallarhorn'
token: '${{ secrets.CI_PAT }}'
path: 'gjallarhorn'
- name: Cypress install
uses: cypress-io/github-action@v2
with:
project: gjallarhorn
browser: chrome
record: true
parallel: true
config: pageLoadTimeout=100000,baseUrl=http://localhost:1080
wait-on: 'http://localhost:1080'