test(puppeteer): wait for bot test result (#11322)

Signed-off-by: Rongrong <i@rong.moe>

Signed-off-by: Rongrong <i@rong.moe>
This commit is contained in:
Rongrong
2022-11-23 22:32:15 +00:00
committed by GitHub
parent b9d59de81a
commit 058cec21b7
2 changed files with 12 additions and 24 deletions
+4 -3
View File
@@ -93,9 +93,10 @@ jobs:
run: yarn
- name: Install Chromium
if: ${{ matrix.chromium.dependency != '' }}
# Chromium from Ubuntu is too old (85), but can still pass the tests
# That's not really a problem since Chromium-bundled Docker image is based on Debian bullseye,
# which updates Chromium frequently, and only on arm/arm64 the image needs Chromium from Debian.
# 'chromium-browser' from Ubuntu APT repo is a dummy package. Its version (85.0.4183.83) means
# nothing since it calls Snap (disgusting!) to install Chromium, which should be up-to-date.
# That's not really a problem since the Chromium-bundled Docker image is based on Debian bullseye,
# which provides up-to-date native packages.
run: |
set -ex
curl -s "https://dl.google.com/linux/linux_signing_key.pub" | gpg --dearmor |
+8 -21
View File
@@ -1,6 +1,5 @@
let puppeteer;
const wait = require('../../lib/utils/wait');
const cheerio = require('cheerio');
let browser = null;
@@ -47,38 +46,26 @@ describe('puppeteer', () => {
puppeteer = require('../../lib/utils/puppeteer');
browser = await puppeteer({ stealth: false });
const page = await browser.newPage();
await page.goto('https://bot.sannysoft.com');
const html = await page.evaluate(() => document.body.innerHTML);
const $ = cheerio.load(html);
browser.close();
browser = null;
const webDriverTest = $('tbody tr').eq(2).find('td').eq(1).text().trim();
const chromeTest = $('tbody tr').eq(4).find('td').eq(1).text().trim();
await page.goto('https://bot.sannysoft.com', { waitUntil: 'networkidle0' });
// page rendering is not instant, wait for expected elements to appear
const [webDriverTest, chromeTest] = await Promise.all(['webdriver', 'chrome'].map((t) => page.waitForSelector(`td#${t}-result.result.failed`).then((hd) => hd.evaluate((e) => e.textContent))));
// the website return empty string from time to time for no reason
// since we don't really care whether puppeteer without stealth passes the bot test, just let it go
expect(['present (failed)', '']).toContain(webDriverTest);
expect(['missing (failed)', '']).toContain(chromeTest);
}, 10000);
}, 15000);
it('puppeteer with stealth', async () => {
puppeteer = require('../../lib/utils/puppeteer');
browser = await puppeteer({ stealth: true });
const page = await browser.newPage();
await page.goto('https://bot.sannysoft.com');
const html = await page.evaluate(() => document.body.innerHTML);
const $ = cheerio.load(html);
browser.close();
browser = null;
const webDriverTest = $('tbody tr').eq(2).find('td').eq(1).text().trim();
const chromeTest = $('tbody tr').eq(4).find('td').eq(1).text().trim();
await page.goto('https://bot.sannysoft.com', { waitUntil: 'networkidle0' });
// page rendering is not instant, wait for expected elements to appear
const [webDriverTest, chromeTest] = await Promise.all(['webdriver', 'chrome'].map((t) => page.waitForSelector(`td#${t}-result.result.passed`).then((hd) => hd.evaluate((e) => e.textContent))));
// these are something we really care about
expect(webDriverTest).toBe('missing (passed)');
expect(chromeTest).toBe('present (passed)');
}, 10000);
}, 15000);
it('puppeteer accept proxy uri', async () => {
process.env.PROXY_URI = 'http://user:pass@rsshub.proxy:2333';