Skip to content
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

Method of harness not always working #178

Open
Heines1983 opened this issue Apr 8, 2022 · 1 comment
Open

Method of harness not always working #178

Heines1983 opened this issue Apr 8, 2022 · 1 comment
Labels
bug Something isn't working cypress-harness

Comments

@Heines1983
Copy link

I'm starting to use Cypress and the harness devkit because of the deprecation of Protractor. I'm currently facing the following issue when invoking methods on a harness.

This is my test:

`describe('Test with harness', () => {

before(() => {
    cy.login()
  });
  
it('should go to the properties page', () => {
    cy.visit('/admin/content-properties').then(() => {
        cy.wait(6000);
    });
})

it('should click a menu item but fails', () => {
    const list = getHarness(ItemMenuComponentHarness);
    list.getItems({label: 'Category'})[0].clickOnItem();
})

it('should click a menu item and succeeds', () => {
    const item = getHarness(ItemMenuItemComponentHarness.with({label: 'Category'}));
    item.clickOnItem();
})

it('should select a tab but fails', () => {

    const tab = getHarness(MatTabHarness.with({label: 'Type specific settings'}));
    tab.select();
})

it('should select a tab and succeeds with the use of pipe', () => {
    const tab = getHarness(MatTabHarness.with({label: 'Type specific settings'}));
    tab.pipe(t => t.select());
})

})`

There are 2 cases in which the method is not working the way I would expect.

The first case is when i'm getting a harness, invoke a method on it (getItems) and on that result I also invoke a method. This throws an error:

image

If I use the same method directly on the harness (2nd test case) it works as expected.

The second case is when the method is also a cypress method like click or select. I get this error:

image

In both cases I can use pipe to make it work, but I would be better if it just works without also.

@yjaaidi
Copy link
Member

yjaaidi commented May 13, 2022

Hi @Heines1983, sorry for responding so late.
Concerning your first issue, this is actually related to the fact that you are using a synchronous access [0] on getItems() return value... while the return value is not an array. It's a cypress wrapper.

I've got to check this but this could work with .eq(0) instead of [0].
Otherwise, you can use the pipe method to chain operations.

...getItems().pipe(items => items[0]).clickOnItem()

Concerning the second issue, Cypress methods gain precendency so you have a collision between cypress's select and the harness's select. Could you try replacing select with .invoke('select') or simply .pipe(el => el.select()) as the previous issue.

@edbzn edbzn added bug Something isn't working cypress-harness labels May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cypress-harness
Projects
None yet
Development

No branches or pull requests

3 participants