量角器不能执行点击<li>标签。

问题描述 投票:0回答:1

我正在尝试做一个e2e测试我的应用程序,但我不能执行点击搜索引擎.这是一个例子,我想尝试 "点击 "的第一个元素,但量角器卡在下面的图像。

enter image description here

我正在谈论的网站是这样的。https:/rent.decathlon.it.

结果是超时错误,所以该元素没有被点击。

这是protractor代码:

import { AppPage } from './app.po';
import {browser, by, element, logging} from 'protractor';
import {SearchBoxWizard} from '../elements/searchbox_wizard';

describe('workspace-project App', () => {
  let page: AppPage;

  beforeEach(() => {
    page = new AppPage();
  });

  it('shoud open select item', async () => {
    await page.navigateTo();
    browser.sleep(500);
    const searchBoxWizardElements = new SearchBoxWizard();
    await searchBoxWizardElements.getLocationInput().click();
    await searchBoxWizardElements.getLocationInput().clear();
    await searchBoxWizardElements.getLocationInput().sendKeys('Milano');
    await browser.sleep(500);
    element(by.css(`.autocomplete-search > ul > li:nth-child(1) > span`)).click();
  });

  afterEach(async () => {
    // Assert that there are no errors emitted from the browser
    const logs = await browser.manage().logs().get(logging.Type.BROWSER);
    expect(logs).not.toContain(jasmine.objectContaining({
      level: logging.Level.SEVERE,
    } as logging.Entry));
  });
});

有人知道为什么吗?

我正在使用这个堆栈。

  • Angular 8
  • 量角器
  • Karma 4.1
  • Jasmin 3

祝贺

编辑 :

我注意到一个非常奇怪的行为,如果我检查是否显示主体,量角器看不到,这是代码......

  it('shoud open select item', async () => {
    await page.navigateTo();
    const searchBoxWizardElements = new SearchBoxWizard();
    const cookiePolicy = new CookiePolicy();
    await cookiePolicy.getAcceptCta().click();
    await searchBoxWizardElements.getLocationInput().click();
    await searchBoxWizardElements.getLocationInput().clear();
    await searchBoxWizardElements.getLocationInput().sendKeys('Milano').then(
      async _ => {
        await browser.sleep(2500);
        await element(by.css('body')).isDisplayed();
      });
  });

我想这是类似于 "失去 "应用焦点的行为... ... 我不知道...

你有什么想法吗?

谢谢

javascript angular protractor e2e-testing angular-e2e
1个回答
-1
投票
  1. 这绝对是一个谷歌的api。我检查了这一点。请求来自 https://maps.googleapis.com/maps/api/place/js
  2. 你错过了 await 在很多地方。你需要阅读关于承诺和处理的方式是与 await

browser.sleep 需要 await

.click() 需要 await

© www.soinside.com 2019 - 2024. All rights reserved.