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

The code examples below show how to run the Actor and get its results. To run the code, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token, which you can find under Settings > Integrations in Apify Console. Learn more

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