Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

chore: fix e2e tests after the documentation cleanup (#3069)

Jindřich Bär6a7248cf25f2
diff --git a/test/e2e/cheerio-curl-impersonate-ts/actor/main.ts b/test/e2e/cheerio-curl-impersonate-ts/actor/main.ts
index d84e8014b..f51d11483 100644
--- a/test/e2e/cheerio-curl-impersonate-ts/actor/main.ts
+++ b/test/e2e/cheerio-curl-impersonate-ts/actor/main.ts
@@ -161,45 +161,28 @@ class CurlImpersonateHttpClient implements BaseHttpClient {
}
}
-function getHttpBinUrl(path: string): string {
- let url: URL;
- if (process.env.APIFY_HTTPBIN_TOKEN) {
- url = new URL(path, 'https://httpbin.apify.actor');
- url.searchParams.set('token', process.env.APIFY_HTTPBIN_TOKEN);
- } else {
- url = new URL(path, 'https://httpbin.org');
- }
-
- return url.href;
-}
-
const crawler = new CheerioCrawler({
async requestHandler(context) {
const { body: text } = await context.sendRequest({
- url: getHttpBinUrl('/uuid'),
- });
-
- const { body: json } = await context.sendRequest({
- url: getHttpBinUrl('/uuid'),
- responseType: 'json',
+ url: 'https://api.apify.com/v2/browser-info',
});
- const { body: ua } = await context.sendRequest<Dictionary>({
- url: getHttpBinUrl('/user-agent'),
+ const { body: json } = await context.sendRequest<Dictionary>({
+ url: 'https://api.apify.com/v2/browser-info',
responseType: 'json',
});
await context.pushData({
body: context.body,
title: context.$('title').text(),
- userAgent: ua['user-agent'],
- uuidTextResponse: text,
- uuidJsonResponse: json,
+ userAgent: json.headers['user-agent'],
+ clientIpTextResponse: text,
+ clientIpJsonResponse: json,
});
},
httpClient: new CurlImpersonateHttpClient({ impersonate: 'chrome-116' }),
});
-await crawler.run([getHttpBinUrl('/')]);
+await crawler.run(['https://crawlee.dev']);
await Actor.exit({ exit: Actor.isAtHome() });
diff --git a/test/e2e/cheerio-curl-impersonate-ts/test.mjs b/test/e2e/cheerio-curl-impersonate-ts/test.mjs
index 3ff4628a3..52bf989d2 100644
--- a/test/e2e/cheerio-curl-impersonate-ts/test.mjs
+++ b/test/e2e/cheerio-curl-impersonate-ts/test.mjs
@@ -11,11 +11,11 @@ await expect(datasetItems.length === 1, 'A dataset item was pushed');
const result = datasetItems[0];
expect(result.body.length > 1000, 'HTML response is not empty');
-expect(result.title === 'httpbin.org', 'HTML title is correct');
+expect(result.title.toLowerCase().includes('crawlee'), 'HTML title is correct');
expect(
result.userAgent ===
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
'User agent is chrome',
);
-expect(result.uuidJsonResponse.uuid !== undefined, 'JSON response contains UUID');
-expect(JSON.parse(result.uuidTextResponse).uuid !== undefined, 'Text response contains UUID');
+expect(result.clientIpJsonResponse.clientIp !== undefined, 'JSON response contains client IP');
+expect(JSON.parse(result.clientIpTextResponse).clientIp !== undefined, 'Text response contains client IP');
diff --git a/test/e2e/cheerio-error-snapshot/actor/main.js b/test/e2e/cheerio-error-snapshot/actor/main.js
index 8448a85fd..988cf66f4 100644
--- a/test/e2e/cheerio-error-snapshot/actor/main.js
+++ b/test/e2e/cheerio-error-snapshot/actor/main.js
@@ -58,6 +58,6 @@ await Actor.main(async () => {
});
await crawler.run(
- Object.values(LABELS).map((label) => ({ url: 'https://example.com', userData: { label }, uniqueKey: label })),
+ Object.values(LABELS).map((label) => ({ url: 'https://crawlee.dev', userData: { label }, uniqueKey: label })),
);
}, mainOptions);
diff --git a/test/e2e/cheerio-impit-ts/actor/main.ts b/test/e2e/cheerio-impit-ts/actor/main.ts
index 8a1b32a19..a4cccb647 100644
--- a/test/e2e/cheerio-impit-ts/actor/main.ts
+++ b/test/e2e/cheerio-impit-ts/actor/main.ts
@@ -10,45 +10,28 @@ if (process.env.STORAGE_IMPLEMENTATION === 'LOCAL') {
await Actor.init();
}
-function getHttpBinUrl(path: string): string {
- let url: URL;
- if (process.env.APIFY_HTTPBIN_TOKEN) {
- url = new URL(path, 'https://httpbin.apify.actor');
- url.searchParams.set('token', process.env.APIFY_HTTPBIN_TOKEN);
- } else {
- url = new URL(path, 'https://httpbin.org');
- }
-
- return url.href;
-}
-
const crawler = new CheerioCrawler({
async requestHandler(context) {
const { body: text } = await context.sendRequest({
- url: getHttpBinUrl('/uuid'),
- });
-
- const { body: json } = await context.sendRequest({
- url: getHttpBinUrl('/uuid'),
- responseType: 'json',
+ url: 'https://api.apify.com/v2/browser-info',
});
- const { body: ua } = await context.sendRequest<Dictionary>({
- url: getHttpBinUrl('/user-agent'),
+ const { body: json } = await context.sendRequest<Dictionary>({
+ url: 'https://api.apify.com/v2/browser-info',
responseType: 'json',
});
await context.pushData({
body: context.body,
title: context.$('title').text(),
- userAgent: ua['user-agent'],
- uuidTextResponse: text,
- uuidJsonResponse: json,
+ userAgent: json.headers['user-agent'],
+ clientIpTextResponse: text,
+ clientIpJsonResponse: json,
});
},
httpClient: new ImpitHttpClient({ browser: Browser.Firefox }),
});
-await crawler.run([getHttpBinUrl('/')]);
+await crawler.run(['https://crawlee.dev']);
await Actor.exit({ exit: Actor.isAtHome() });
diff --git a/test/e2e/cheerio-impit-ts/test.mjs b/test/e2e/cheerio-impit-ts/test.mjs
index 3ee48b537..8602dbdb5 100644
--- a/test/e2e/cheerio-impit-ts/test.mjs
+++ b/test/e2e/cheerio-impit-ts/test.mjs
@@ -11,7 +11,7 @@ await expect(datasetItems.length === 1, 'A dataset item was pushed');
const result = datasetItems[0];
expect(result.body.length > 1000, 'HTML response is not empty');
-expect(result.title === 'httpbin.org', 'HTML title is correct');
+expect(result.title.toLowerCase().includes('crawlee'), 'HTML title is correct');
expect(/Gecko\/\d{8} Firefox\/\d{2}/.test(result.userAgent), 'Impit correctly spoofs Firefox');
-expect(result.uuidJsonResponse.uuid !== undefined, 'JSON response contains UUID');
-expect(JSON.parse(result.uuidTextResponse).uuid !== undefined, 'Text response contains UUID');
+expect(result.clientIpJsonResponse.clientIp !== undefined, 'JSON response contains client IP');
+expect(JSON.parse(result.clientIpTextResponse).clientIp !== undefined, 'Text response contains client IP');
diff --git a/test/e2e/cheerio-page-info/actor/main.js b/test/e2e/cheerio-page-info/actor/main.js
index f82298872..fbc87f3c4 100644
--- a/test/e2e/cheerio-page-info/actor/main.js
+++ b/test/e2e/cheerio-page-info/actor/main.js
@@ -40,5 +40,5 @@ await Actor.main(async () => {
requestHandler: router,
});
- await crawler.run([{ url: 'https://crawlee.dev/js/docs/3.0/examples', userData: { label: 'START' } }]);
+ await crawler.run([{ url: 'https://crawlee.dev/js/docs/3.12/examples', userData: { label: 'START' } }]);
}, mainOptions);
diff --git a/test/e2e/playwright-default/actor/main.js b/test/e2e/playwright-default/actor/main.js
index bdda681cf..fdda97cad 100644
--- a/test/e2e/playwright-default/actor/main.js
+++ b/test/e2e/playwright-default/actor/main.js
@@ -21,10 +21,10 @@ await Actor.main(async () => {
const pageTitle = await page.title();
await Dataset.pushData({ url, pageTitle });
await enqueueLinks({
- globs: ['**/3.0/examples/*'],
+ globs: ['**/3.12/examples/*'],
});
},
});
- await crawler.run(['https://crawlee.dev/js/docs/3.0/examples/']);
+ await crawler.run(['https://crawlee.dev/js/docs/3.12/examples/']);
}, mainOptions);
diff --git a/test/e2e/playwright-default/test.mjs b/test/e2e/playwright-default/test.mjs
index b82824ae1..1bc882da6 100644
--- a/test/e2e/playwright-default/test.mjs
+++ b/test/e2e/playwright-default/test.mjs
@@ -6,5 +6,5 @@ await initialize(testActorDirname);
const { stats, datasetItems } = await runActor(testActorDirname, 16384);
await expect(stats.requestsFinished > 15, 'All requests finished');
-await expect(datasetItems.length > 15 && datasetItems.length < 25, 'Number of dataset items');
+await expect(datasetItems.length > 15 && datasetItems.length < 30, 'Number of dataset items');
await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');
diff --git a/test/e2e/playwright-multi-run/actor/main.js b/test/e2e/playwright-multi-run/actor/main.js
index 97b23ecc4..e47305cec 100644
--- a/test/e2e/playwright-multi-run/actor/main.js
+++ b/test/e2e/playwright-multi-run/actor/main.js
@@ -15,16 +15,16 @@ const crawler = new PlaywrightCrawler({
const pageTitle = await page.title();
await Dataset.pushData({ url, pageTitle });
await enqueueLinks({
- globs: ['**/3.0/examples/*'],
+ globs: ['**/3.12/examples/*'],
});
},
});
crawler.log.info('=== Run 1 ===');
-await crawler.run(['https://crawlee.dev/js/docs/3.0/examples']);
+await crawler.run(['https://crawlee.dev/js/docs/3.12/examples']);
crawler.log.info('=== Run 2 ===');
-await crawler.run(['https://crawlee.dev/js/docs/3.0/examples']);
+await crawler.run(['https://crawlee.dev/js/docs/3.12/examples']);
crawler.log.info('=== Run 3 ===');
-await crawler.run(['https://crawlee.dev/js/docs/3.0/examples']);
+await crawler.run(['https://crawlee.dev/js/docs/3.12/examples']);
await Actor.exit({ exit: Actor.isAtHome() });
diff --git a/test/e2e/puppeteer-default/actor/main.js b/test/e2e/puppeteer-default/actor/main.js
index 46d92d652..fd8a6fb8f 100644
--- a/test/e2e/puppeteer-default/actor/main.js
+++ b/test/e2e/puppeteer-default/actor/main.js
@@ -22,10 +22,10 @@ await Actor.main(async () => {
const pageTitle = await page.title();
await Dataset.pushData({ url, pageTitle });
await enqueueLinks({
- globs: ['**/3.0/examples/*'],
+ globs: ['**/3.12/examples/*'],
});
},
});
- await crawler.run(['https://crawlee.dev/js/docs/3.0/examples/']);
+ await crawler.run(['https://crawlee.dev/js/docs/3.12/examples/']);
}, mainOptions);
diff --git a/test/e2e/puppeteer-default/test.mjs b/test/e2e/puppeteer-default/test.mjs
index b82824ae1..1bc882da6 100644
--- a/test/e2e/puppeteer-default/test.mjs
+++ b/test/e2e/puppeteer-default/test.mjs
@@ -6,5 +6,5 @@ await initialize(testActorDirname);
const { stats, datasetItems } = await runActor(testActorDirname, 16384);
await expect(stats.requestsFinished > 15, 'All requests finished');
-await expect(datasetItems.length > 15 && datasetItems.length < 25, 'Number of dataset items');
+await expect(datasetItems.length > 15 && datasetItems.length < 30, 'Number of dataset items');
await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');
diff --git a/test/e2e/puppeteer-error-snapshot/actor/main.js b/test/e2e/puppeteer-error-snapshot/actor/main.js
index 984c5238e..6ee43c8ef 100644
--- a/test/e2e/puppeteer-error-snapshot/actor/main.js
+++ b/test/e2e/puppeteer-error-snapshot/actor/main.js
@@ -57,6 +57,6 @@ await Actor.main(async () => {
});
await crawler.run(
- Object.values(LABELS).map((label) => ({ url: 'https://example.com', userData: { label }, uniqueKey: label })),
+ Object.values(LABELS).map((label) => ({ url: 'https://crawlee.dev', userData: { label }, uniqueKey: label })),
);
}, mainOptions);
diff --git a/test/e2e/puppeteer-page-info/actor/main.js b/test/e2e/puppeteer-page-info/actor/main.js
index 95ca1f971..88fd1b9d8 100644
--- a/test/e2e/puppeteer-page-info/actor/main.js
+++ b/test/e2e/puppeteer-page-info/actor/main.js
@@ -43,5 +43,5 @@ await Actor.main(async () => {
},
});
- await crawler.run([{ url: 'https://crawlee.dev/docs/3.0/examples', userData: { label: 'START' } }]);
+ await crawler.run([{ url: 'https://crawlee.dev/docs/3.12/examples', userData: { label: 'START' } }]);
}, mainOptions);
diff --git a/test/e2e/request-queue-zero-concurrency/actor/main.js b/test/e2e/request-queue-zero-concurrency/actor/main.js
index 49eee8136..13a8aa8cd 100644
--- a/test/e2e/request-queue-zero-concurrency/actor/main.js
+++ b/test/e2e/request-queue-zero-concurrency/actor/main.js
@@ -16,9 +16,9 @@ const mainOptions = {
// RequestQueue auto-reset when stuck with requests in progress
await Actor.main(async () => {
const requestQueue = await RequestQueueV1.open();
- await requestQueue.addRequest({ url: 'https://example.com/?q=1' });
- await requestQueue.addRequest({ url: 'https://example.com/?q=2' });
- const r3 = await requestQueue.addRequest({ url: 'https://example.com/?q=3' });
+ await requestQueue.addRequest({ url: 'https://crawlee.dev/?q=1' });
+ await requestQueue.addRequest({ url: 'https://crawlee.dev/?q=2' });
+ const r3 = await requestQueue.addRequest({ url: 'https://crawlee.dev/?q=3' });
// trigger 0 concurrency by marking one of the requests as already in progress
requestQueue.inProgress.add(r3.requestId);
diff --git a/test/e2e/request-skip-navigation/actor/main.js b/test/e2e/request-skip-navigation/actor/main.js
index e34dfc2c9..6ab632190 100644
--- a/test/e2e/request-skip-navigation/actor/main.js
+++ b/test/e2e/request-skip-navigation/actor/main.js
@@ -4,19 +4,19 @@ import { CheerioCrawler, Dataset, log, Request } from '@crawlee/cheerio';
log.setLevel(log.LEVELS.DEBUG);
const r1 = new Request({
- url: 'https://example.com/?q=1',
+ url: 'https://crawlee.dev/?q=1',
skipNavigation: true,
userData: { abc: { def: 'ghi' } },
});
const r2 = new Request({
- url: 'https://example.com/?q=2',
+ url: 'https://crawlee.dev/?q=2',
skipNavigation: true,
});
r2.userData = { xyz: { kjl: 'mno' } };
const r3 = new Request({
- url: 'https://example.com/?q=3',
+ url: 'https://crawlee.dev/?q=3',
});
const mainOptions = {