當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。