Search code examples
angularbrowserautomationactione2e-testing

browser actions doesn't work in headless chrome


In angular test automation, I am using some mouse and keyboard actions i.e mouseDown, Key.ENTER and Key.ARROW_DOWN in my it block. It superbly works in browser (actual browser). The same test case fails and I am sure it fails due to browser.actions().SOMEACTION() in headless browser. I have searched but didn't find any solution. Attached is the file for failing test case. Will be thankful for your kind help.

it('Should add Dispatcher successfully',()=>{
        return new Promise((res)=>{
            let email = Math.floor(Math.random()*100000)+1;
            addMember.getAddMemberSubMenu().click().then(()=>{
                setTimeout(()=>{
                    addMember.getFirstNameInput().sendKeys("John"); 
                    addMember.getLastNameInput().sendKeys("Doe");
                    addMember.getEmailInput().sendKeys(email+"@gmail.com")              addMember.getUserRolesInput().element(by.cssContainingText('option','Dispatcher')).click();
                    addMember.getPhoneNumberInput().sendKeys('03133535058');
                               browser.actions().mouseDown(addMember.getLocationInput()).perform(); //problem starts here
                    browser.actions().sendKeys(Key.ARROW_DOWN).perform();
                    browser.actions().sendKeys(Key.ENTER).perform();
                    addMember.getSaveButton().click().then(()=>{
                    return new Promise((resolve)=>{
                        setTimeout(()=>{
                        expect(browser.getCurrentUrl()).toContain('people').then(()=>{
                            resolve();
                            res();
                            });
                        },browser.params.Waiting_time.HIGH);
                    });
                });
             },browser.params.Waiting_time.HIGH);
            })
        });
    });


Solution

  • I solved this by passing window size argument in chromeOptions as

    capabilities: {
      chromeOptions: {
        args: [ "--headless","--window-size=1600x1200"] //window-size
      },
    browserName: 'chrome'
    

    },