Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
29 changes: 8 additions & 21 deletions test/utils/puppeteer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
let puppeteer;
const wait = require('../../lib/utils/wait');
const cheerio = require('cheerio');

let browser = null;

Expand Down Expand Up @@ -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';
Expand Down