0
votes

i want to enter a keyboard input - TAB or ENTER in a protractor e2e test. Ive tried using the below examples, but the TAB or ENTER input is never registered. I can input the text with sendKeys in my origin and destination fields and i can click my search button, but the search never really executes, because ENTER or TAB was never registered. I have tried these options for keyboard input:

page.getOrigin().sendKeys(protractor.Key.ENTER); page.getOrigin().sendKeys(protractor.Key.ENTER).perform();

protractor - 5.3.1

spec.ts

import { PageObject } from './playground.po'; import { browser, by, element, ExpectedConditions, $, protractor } from 'protractor'; import { Config } from 'protractor';

describe('test', () => { let page: PageObject;

;

  beforeEach(() => {

    page = new PageObject();
    browser.waitForAngularEnabled(false);
    browser.get(browser.params.baseUrl);

  });


 it('a search in USA', () => {
    browser.sleep(1 * 2000);

    page.getOrigin().clear();
    page.getOrigin().sendKeys('California');
    page.getOrigin().sendKeys(protractor.Key.ENTER);

    page.getDestination().clear();
    page.getDestination().sendKeys('Boston');
    page.getDestination().sendKeys(protractor.Key.ENTER);

    page.getSearchButton().click();
    browser.sleep(1 * 2000);

  });

pageObject

import { browser, by, element } from 'protractor';

export class PageObject {

  getOrigin() {
    return element(by.className('originSearch')).element(by.name('origin'));
  }
  getDestination() {
    return element(by.className('destinationSearch')).element(by.name('destination'));
  }
  getSearchButton() {
    return element(by.css('div.searchButton'));
  }
}
1
you can try send TAB and ENTER on other website, i think it should work. your issue not caused by protractor, should be some special thing on the app, like auto suggestion list, input valid added by app developer. Could you give the app url? - yong
yes, there is an auto suggestion list. Even though it selects the item i want from the list and i can TAB or ENTER out, it doesnt seem to register the input. - user6086008
ok, try add a along sleep like 10 or 15 seconds before click the button in your code. - yong

1 Answers

0
votes

You should try chaining them together, like so:

page.getOrigin().clear().sendKeys('California').sendKeys(protractor.Key.ENTER);

This should ensure that they're executed in the correct order.