-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fixtures aliasing not working as expected? #948
Comments
Not a bug. Cypress commands are async. It's impossible for This doc explains this exact scenario: https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Aliases |
The reason OP probably though it was a bug is because the docs for fixture claim the following is valid on it's own: cy.fixture('users.json').as('usersData') |
It is valid on its own, so long as by the time you access it with Alternatively you could use |
I agree, the doc isn't clear about that. I did the same mistake. |
I created a new issue in our docs to document this better here: cypress-io/cypress-documentation#722. Our documentation is open source and contributions are welcome. 😄 |
@brian-mann Any idea why this is not working (v3.1.0): describe('Knowledge Base Application', () => {
before(() => {
cy.fixture('users/admin').as('adminData')
})
it('test1', () => {
cy.get('@adminData')
.then(adminData => { // able to read adminData
cy.log(adminData)
})
})
it('test2', () => {
cy.get('@adminData')
.then(adminData => { // **throws exception: CypressError: cy.get() could not find a registered alias for: '@adminData'. You have not aliased anything yet.**
cy.log(adminData)
})
})
}) This works fine if I move the fixture setup from before to beforeEach. |
@aaditya-kumar-harness For some reason the fixtures you are initializing in before() method will only be accessable from the first test (Cypress implemented it like that.) If you want to access from all of it, you have to use beforeEach. |
@aaditya-kumar-harness relevant thread: #665 |
It works. Being asynchronous you have to wait for the fixture to be loaded cy.fixture("users/admin.json").as("admin")
cy.get('@admin')
.then((admin) => {
cy.get("#selector1")
.type(admin.username)
cy.get("#selector2")
.type(admin.password)
}) |
Can someone tell why i am getting "Cannot read property testadata of undefined? describe('Testing system', function () {
beforeEach(function () {
cy.visit('/')
cy.wait(3000)
})
beforeEach(function () {
cy.fixture('testdata').then(function (testdata) {
this.testdata = testdata
})
})
it('Finding all dictionaries with an asterisk', function () {
cy.get('.nav-link[title="Słowniki"]').click()
cy.get('.sub-menu li').then(($divs) => {
Cypress._.each(this.testdata.list, (tag) => {
expect($divs).to.contain(tag)
})
})
cy.log('List length', this.testdata.list.length)
})
it('Testing specific dictionary', function () {
cy.get('.nav-link[title="Słowniki"]').click()
for (var i = 0; i < this.testdata.list.length; i++) {
cy.wait(3000)
cy.get(`.sub-menu`).contains(this.testdata.list[i]).click()
cy.url().should('include', this.testdata.listurl[i])
if(this.testdata.listurl[i] === '/slowniki/bramy-wjzadowe' || this.testdata.listurl[i] === '/slowniki/gatunek-produktu'){
cy.log("'Słownik nie posiada kolumn Aktywny', 'użytkownik modyfikujący' oraz 'data ostaniej modyfikacji'")
} else {
cy.get('.dx-row td[aria-label="Column Aktywny?"]').should('have.text', 'Aktywny?')
}
}
})
}) |
@padifu You need to alias the fixture using the cy.fixture('testdata').as('testdata') You may want to try asking our community in our GitHub Discussions. As an open source project with a small maintainer team we have to focus our time on bugs and features in the product, which Issues are reserved for. |
This solution is not working, how should i call data ? Just simple testdata.nameofdata ? |
Is this a Feature or Bug?
Probably a bug
Current behavior:
When using
cy.fixture("users/admin").as("adminData");
I can't access adminDataDesired behavior:
I should be able to access
this.adminData
How to reproduce:
Call
this.adminData.email
after a fixture has been aliasedTest code:
Fixture code
cypress/fixtures/users/admin.js
The text was updated successfully, but these errors were encountered: