当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ElementFinder.getLocation方法代码示例

本文整理汇总了TypeScript中protractor.ElementFinder.getLocation方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ElementFinder.getLocation方法的具体用法?TypeScript ElementFinder.getLocation怎么用?TypeScript ElementFinder.getLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在protractor.ElementFinder的用法示例。


在下文中一共展示了ElementFinder.getLocation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: isVisibleInViewport

/** Checks if the given element is visible in the given viewport. */
async function isVisibleInViewport(el: ElementFinder, viewport: ElementFinder): Promise<boolean> {
  if (!await el.isPresent() || !await el.isDisplayed() || !await viewport.isPresent() ||
      !await viewport.isDisplayed()) {
    return false;
  }
  const viewportRect = getRect(await viewport.getLocation(), await viewport.getSize());
  const elRect = getRect(await el.getLocation(), await el.getSize());
  return elRect.left < viewportRect.right && elRect.right > viewportRect.left &&
      elRect.top < viewportRect.bottom && elRect.bottom > viewportRect.top;
}
开发者ID:Nodarii,项目名称:material2,代码行数:11,代码来源:virtual-scroll.e2e.spec.ts

示例2: it

  it('should scroll to seventh heading from button with custom easing', () => {
    const target: ElementFinder = element(by.css('#head7'));
    const trigger: ElementFinder = element(by.css('#customEasingButton'));
    const pageScrollDuration = 1250;
    target.getLocation().then((headingLocation: any) => {
      page.getScrollPos().then((initialPos: number) => {
        expect(initialPos).toEqual(0);
        // Make sure the browser logs are empty so get them once (which automatically clears them)
        // Source: http://stackoverflow.com/a/30589885
        browser.manage().logs().get('browser').then(() => {
          trigger.sendKeys(protractor.Key.ENTER).then(() => {
            browser.sleep(pageScrollDuration).then(() => {
              // At the end of the time the scrolling should be at the specific target position
              page.getScrollPos().then((pos: number) => {
                expect(pos).toBeCloseTo(Math.round(headingLocation.y), Closeness.ofByOne);
              });
              // Inspect the console logs, they should contain all in between scroll positions
              // Using the browser.sleep() to execute some code while the animation is running does not work
              // consistently across browser, especially causing problems with the CI server
              browser.manage().logs().get('browser').then(browserLog => {
                const scrollPositionHistory = browserLog
                  .filter(log => log.message.indexOf('Scroll Position: ') >= 0) // only take scroll position logs
                  .map(log => parseInt(log.message.split(' ').reverse()[0], 10)); // parse scroll logs into ints

                expect(scrollPositionHistory.length).toBeGreaterThan(0);

                const averageScrollPosChange = scrollPositionHistory[scrollPositionHistory.length - 1]
                  / scrollPositionHistory.length;

                // For the first quarter check that the scrollPosChange is below the linear average
                const firstQuarterEnd = Math.round(scrollPositionHistory.length * 0.25);
                for (let i = 0; i < firstQuarterEnd; i++) {
                  const scrollPosChange = scrollPositionHistory[i + 1] - scrollPositionHistory[i];
                  expect(scrollPosChange).toBeLessThan(averageScrollPosChange);
                }

                // For the 20% in the middle check that the scrollPosChange is above the linear average
                const center20PercentStart = Math.round(scrollPositionHistory.length * 0.4);
                const center20PercentEnd = Math.round(scrollPositionHistory.length * 0.6);
                for (let i = center20PercentStart; i < center20PercentEnd; i++) {
                  const scrollPosChange = scrollPositionHistory[i + 1] - scrollPositionHistory[i];
                  expect(scrollPosChange).toBeGreaterThan(averageScrollPosChange);
                }

                // For the last quarter again check that the scrollPosChange is below the linear one
                const lastQuarterStart = Math.round(scrollPositionHistory.length * 0.75);
                for (let i = lastQuarterStart; i < scrollPositionHistory.length - 2; i++) {
                  const scrollPosChange = scrollPositionHistory[i + 1] - scrollPositionHistory[i];
                  expect(scrollPosChange).toBeLessThan(averageScrollPosChange);
                }
              });
            });
          });
        });
      });
    });
  });
开发者ID:Nolanus,项目名称:ng2-page-scroll,代码行数:57,代码来源:easing-functions.e2e-spec.ts

示例3: expectMenuLocation

 expectMenuLocation(el: ElementFinder, {x, y}: {x: number, y: number}) {
   el.getLocation().then(loc => {
     expect(loc.x).toEqual(x, 'Expect the x-position to be equal');
     expect(loc.y).toEqual(y, 'Expect the y-position to be equal');
   });
 }
开发者ID:BernhardRode,项目名称:material2,代码行数:6,代码来源:menu-page.ts

示例4: scrollToElement

 scrollToElement(elm: ElementFinder): promise.Promise<{}> {
   return elm.getLocation().then((loc) => {
     return browser.driver.executeScript('window.scrollTo(0,arguments[0]);', loc.y);
   });
 }
开发者ID:Nolanus,项目名称:ng2-page-scroll,代码行数:5,代码来源:app.po.ts


注:本文中的protractor.ElementFinder.getLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。