Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.86 KB | None | 0 0
  1. let mobileJsTestFunc = function (chain, test) {
  2. tools.initTest(test);
  3. tools.openUrlPuppeteer(
  4. { test: test,
  5. preCatchRe: [
  6. /\/collect?.*&t=pageview/,
  7. /\/collect?.*&t=event.*&ea=layout_dimension.*=prism/,
  8. /session_tr.+t=\d+&session=[^&]+&site=\d+&expid=0/,
  9. /amp-carousel-0\.1\.js/
  10. ]
  11. }, async function (page, harLogFilePath, browser) {
  12. const params = test.params;
  13. const pages = params.pages;
  14. const ads = params.ads;
  15.  
  16. await page.setDefaultNavigationTimeout(20000);
  17. await page.setDefaultTimeout(20000);
  18. await page.waitFor(waitBeforeTest);
  19.  
  20. /* Проверяем что наш скрипт сгенерил свайп-навигацию
  21. * Ожидаемый результат: Кол-во буллитов для свайпа 7*/
  22. await scrape(['.cl-swipe-holder .cl-swipe-nav > li'], page, test, (result) => {
  23. tools.assert('equal', result['elementData'].length, 7, `Не работает листалка. \nНеправильное количество элементов ${result['selector']}. ${result['url']}`, test);
  24. });
  25.  
  26. /* Проверяем что поиск открывается */
  27. await page.tap('button#cl-search');
  28. await page.waitForSelector('amp-sidebar#cl-sidebar-search:not([hidden])');
  29. await page.waitFor(200);
  30. await page.tap('amp-sidebar#cl-sidebar-search + button.cl-close-sidebar');
  31. await page.waitFor(1000);
  32.  
  33. /* Проверяем что бургер меню открывается */
  34. await page.tap('button#cl-burger');
  35. await page.waitForSelector('amp-sidebar#cl-sidebar:not([hidden])');
  36. await page.waitFor(200);
  37. await page.tap('amp-sidebar#cl-sidebar + button.cl-close-sidebar');
  38.  
  39. await page.waitFor(500);
  40. let testPage = async function(options) {
  41. const divId = options['divId'];
  42. const nextDivId = divId < 3 ? divId + 1 : 1;
  43. const pageId = options['pageId'];
  44. const inarticleCount = options['inarticleCount'];
  45. const doSwipe = options['doSwipe'];
  46. const relatedMinCount = options['relatedMinCount'];
  47.  
  48.  
  49. /* Включаем кетч для скриптов, работающих по скроллу */
  50. if(pageId === 1) {
  51. tools.waitForResponse({re: /page\.js/}, page, test);
  52. tools.waitForResponse({re: /outbrain\.js/}, page, test);
  53. tools.waitForResponse({re: /amp-list-0\.1\.js/}, page, test);
  54. tools.waitForResponse({re: /amp-mustache-0\.2\.js/}, page, test);
  55. // tools.waitForResponse({re: /amp-carousel-0\.1\.js/}, page, test);
  56. }
  57.  
  58. /* Немного ждем прогрузки страницы */
  59. await page.waitFor(300);
  60.  
  61. /* Проверяем что основная картинка загрузилась */
  62. await page.waitForSelector(`#cl-swipe-id${divId} .article-header > amp-img:first-of-type img`);
  63.  
  64. /* Проверяем что картинки через BG загрузились */
  65. // await page.waitForSelector(`#cl-swipe-id${divId} article > .aawp .aawp-product:first-of-type amp-img img`);
  66.  
  67. /* Скроллим страницу */
  68. let scrollPos = 0;
  69. let scrollHeight;
  70.  
  71. while(!scrollHeight || scrollPos < scrollHeight) {
  72. let scrollCurrent = await page.evaluate(() => {
  73. window.scrollBy(0, window.innerHeight);
  74. return {'innerHeight': window.innerHeight, 'scrollHeight': document.body.scrollHeight};
  75. });
  76. await page.waitFor(waitBeforeScrollStep);
  77. scrollHeight = scrollCurrent.scrollHeight;
  78. scrollPos = scrollPos + scrollCurrent.innerHeight;
  79. }
  80. /* Проверяем что отрисовался outbrain */
  81. await page.waitForSelector(`#cl-swipe-id${divId} div.ob-smartfeed-wrapper`);
  82.  
  83. if (typeof ads === 'object') {
  84. if('sticky' in ads) {
  85. /* Проверяем что в стики отрисовался адюнит */
  86. await page.waitForSelector(`#cl-swipe-id${divId} #lx_${ads.sticky} div[id^="google_ads_iframe"]`);
  87.  
  88. /* Проверяем видимость стики-блока для юзера */
  89. tools.checkVisible(`#cl-swipe-id${divId} #lx_${ads.sticky}`, 'Sticky ad unit container is invisible for user', page, test);
  90.  
  91. /* Закрываем стики блок */
  92. await page.tap(`#cl-swipe-id${divId} #lx_${ads.sticky} button#cl_close_button`);
  93.  
  94. /* Проверяем что стики закрылся */
  95. tools.checkInvisible(`#cl-swipe-id${divId} #lx_${ads.sticky}`, 'Sticky ad unit container is invisible for user', page, test);
  96. }
  97.  
  98. if('inarticle' in ads) {
  99. /* Проверяем что отрисовались все инартиклы */
  100. if (inarticleCount) {
  101. for (var i = 1; i < inarticleCount + 1; i++) {
  102. await page.waitForSelector(`#cl-swipe-id${divId} #lx_${ads.inarticle}-${i} div[id^="google_ads_iframe"]`);
  103. }
  104. }
  105. }
  106.  
  107. if('fix' in ads) {
  108. /* Проверяем что отрисовался фикс блок */
  109. await page.waitForSelector(`#cl-swipe-id${divId} #lx_${ads.fix} div[id^="google_ads_iframe"]`);
  110. }
  111. }
  112. if(relatedMinCount > 0){
  113. /* Проверяем наличие инартикл рилейтед блока и кол-во статей внутри */
  114. await scrape([`#cl-swipe-id${divId} .cl-related .i-amphtml-scrollable-carousel-container .articles-list-article__slider`], page, test, result => {
  115. tools.assert('isAtLeast', result['elementData'].length, relatedMinCount, `Страница ${pageId}. В related in-article недостаточно статей (${result['elementData'].length} < ${relatedMinCount}). \nНеправильное количество элементов ${result['selector']}. ${result['url']}`, test);
  116. });
  117.  
  118. /* Проверяем наличие текстов и картинок внутри инартикл блока */
  119. await page.waitForSelector(`#cl-swipe-id${divId} .cl-related .i-amphtml-scrollable-carousel-container div:first-child a.articles-list-article__image`);
  120. await page.waitForSelector(`#cl-swipe-id${divId} .cl-related .i-amphtml-scrollable-carousel-container div:first-child a.articles-list-article__description`);
  121.  
  122. /* Проверяем наличие фикс блока и кол-во статей внутри, наличие заголовка */
  123. await scrape([`#cl-swipe-id${divId} .cl-related div[role=listitem]`], page, test, result => {
  124. tools.assert('isAtLeast', result['elementData'].length, relatedMinCount, `Страница ${pageId}. В related fixed недостаточно статей (${result['elementData'].length} < ${relatedMinCount}). \nНеправильное количество элементов ${result['selector']}. ${result['url']}`, test);
  125. });
  126. await page.waitForSelector(`#cl-swipe-id${divId} .cl-related div[role=listitem]:first-child .cl-related-title`);
  127.  
  128. }
  129.  
  130. /* Проверяем что сгенерились соцкнопки */
  131. // await page.waitForSelector(`#cl-swipe-id${divId} .a2a_kit svg`);
  132.  
  133. /* Проверяем что сгенерился Outbrain */
  134. await page.waitForSelector(`div.ob-widget`);
  135.  
  136. if(doSwipe) {
  137. /* Включаем кетч для скриптов, работающих по свайпу */
  138. tools.waitForResponse({re: /session_tr.+t=\d+&session=[^&]+&site=\d+&expid=0/}, page, test);
  139. tools.waitForResponse({re: new RegExp(`\/collect?.*&t=event.*&ec=navigation.*&ea=swipe_right.*&tid=${params.gaAccountId}.*`)}, page, test);
  140. // tools.waitForResponse({re: /outbrain\.com\/utils\/get/}, page, test);
  141.  
  142. /* Перелистываем страницу кликнув на Next Article */
  143. await page.tap(`#cl-swipe-id${divId} #cl-next-article`);
  144.  
  145. /* Проверяем что следующая страница загрузилась */
  146. await page.waitForSelector(`#cl-swipe-id${nextDivId}.cl-current #cl-shadow-id${nextDivId} main article h1`);
  147. }
  148. };
  149.  
  150. /* Гоняем проверки по страницам */
  151. // console.log(pages.length);
  152. if(pages.length) {
  153. let div = 1;
  154. let i = 1;
  155. let swipe;
  156. for (const page of pages) {
  157. swipe = !(i === pages.length);
  158. // console.log({divId: div, pageId: i, inarticleCount: page.inarticleCount, doSwipe: swipe});
  159. await testPage({
  160. divId: div,
  161. pageId: i,
  162. inarticleCount: page.inarticleCount,
  163. relatedMinCount: page.relatedMinCount,
  164. doSwipe: swipe
  165. });
  166.  
  167. div = div < 3 ? div + 1 : 1;
  168. i++;
  169. }
  170.  
  171. }
  172. });
  173. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement