Actor Testing avatar

Actor Testing

Try for free

No credit card required

View all Actors
Actor Testing

Actor Testing

pocesar/actor-testing
Try for free

No credit card required

Test your actors with varying inputs and expected outputs, duplicates, bad output fields, or unexpected log messages using Jasmine

You can access the Actor Testing programmatically from your own Python applications by using the Apify API. You can also choose the language preference from below. To use the Apify API, you’ll need an Apify account and your API token, found in Integrations settings in Apify Console.

1from apify_client import ApifyClient
2
3# Initialize the ApifyClient with your Apify API token
4# Replace '<YOUR_API_TOKEN>' with your token.
5client = ApifyClient("<YOUR_API_TOKEN>")
6
7# Prepare the Actor input
8run_input = {
9    "testSpec": """({ it, xit, moment, _, run, expect, expectAsync, input, describe }) => {
10    (input.resource ? [
11        'beta',
12    ] : [
13        'latest',
14    ]).forEach((build) => {
15        describe(`${build} version`, () => {
16            it('test something-task', async () => {
17                const runResult = await run({
18                    taskId: '',
19                });
20
21                await expectAsync(runResult).toHaveStatus('SUCCEEDED');
22                await expectAsync(runResult).withLog((log) => {
23                    expect(log)
24                        .withContext(runResult.format('ReferenceError'))
25                        .not.toContain('ReferenceError');
26                    expect(log)
27                        .withContext(runResult.format('TypeError'))
28                        .not.toContain('TypeError');
29                });
30
31                await expectAsync(runResult).withStatistics((stats) => {
32                    expect(stats.requestsRetries)
33                        .withContext(runResult.format('Request retries'))
34                        .toBeLessThan(3);
35
36                    expect(stats.crawlerRuntimeMillis)
37                        .withContext(runResult.format('Run time'))
38                        .toBeWithinRange(0.1 * 60000, 10 * 60000);
39                });
40
41                await expectAsync(runResult).withDataset(({ dataset, info }) => {
42                    expect(info.cleanItemCount)
43                        .withContext(runResult.format('Dataset cleanItemCount'))
44                        .toBeGreaterThan(0);
45
46                    expect(dataset.items)
47                        .withContext(runResult.format('Dataset items array'))
48                        .toBeNonEmptyArray();
49                });
50            });
51        });
52    });
53}""",
54    "slackChannel": "#public-actors-tests-notifications",
55    "slackPrefix": "@lead-dev @actor-owner",
56}
57
58# Run the Actor and wait for it to finish
59run = client.actor("pocesar/actor-testing").call(run_input=run_input)
60
61# Fetch and print Actor results from the run's dataset (if there are any)
62print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
63for item in client.dataset(run["defaultDatasetId"]).iterate_items():
64    print(item)
65
66# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

Actor Testing API in Python

The Apify API client for Python is the official library that allows you to use Actor Testing API in Python, providing convenience functions and automatic retries on errors.

Install the apify-client

pip install apify-client

Other API clients include:

Developer
Maintained by Community
Actor metrics
  • 1 monthly user
  • 9 stars
  • 84.4% runs succeeded
  • Created in Dec 2020
  • Modified 1 day ago
Categories