How to Call the TestFairy SDK with Appium

Sauce AI for Test Authoring: Move from intent to performance in minutes.|xBack to ResourcesBlogPosted<

June 04, 2026 · 6 min read · Tool Comparison

Sauce AI for Test Authoring: Move from intent to performance in minutes.

|

x

Back to Resources

Blog

Posted March 16, 2023

How to Call the TestFairy SDK with Appium

Our nomadic beta testing resolution can help mobile developer and SDETs meliorate their mobile trial mechanisation. In this clause, we extend how to make Appium scripts talking to the TestFairy SDK.

quote

We ’ ve be busy making our wagerer not only for nomadic developers but also for SDETs who are looking for innovative means to get their awesome. The challenge is how to make Appium handwriting talk to the TestFairy SDK. All of the example code in this post is useable asexposed source, so you can copy and adapt it to your need.

Environment

We ’ ll be utiliseWebdriverIOwith JavaScript but all examples can be port to other guest and languages with little to no change. The only requirement in our drivers is the ability to arouse mobile: startService viaexecute()which is already available on the latest UIAutomator2 driver. Ourexam bed appis too included in the repo.

How it Works

Our solution is based on the principle that Appium can start Android service by constructing purport over adb. These aim can throw additional tilt for services to interpret. We ’ ve created a mere service to parse incoming intent data to decide which TestFairy SDK method to invoke.

Every time Appium starts our service, the service read the intent, invokes the TestFairy SDK and discontinue itself once the work is done. The service we launch will not interrupt any of the running activities, giving us the power to use it without change across various types of apps including video games, social networking, and camera apps.

Here are the steps you need to take:

  1. Copy the “ Appium call TestFairy ” fileinto your Android app project.

  2. Add this line to your app manifest:

& lt; service android: exported= & quot; true & quot; android: name= & quot; .TestFairyService & quot; / & gt;

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

Add these helpers to your Appium book. As an model, we ply begin (), stop () and addEvent () but you can easily simulate one of these to add an invocation for other methods as you need. Make certain you update TestFairyService to parse your newly added invocation. Update these functions with your package gens by replacing: com.example.appiumcallstestfairy/.TestFairyService with com.your.package.name/.TestFairyService

1
/**
2
* Starts recording a TestFaiy session.
3
*
4
* @ param client wdio client
5
* @ param appToken TestFairy app token can be base at https: //app.testfairy.com/settings
6
*/
7
async role begin (node, appToken) {
8
client.startActivity ()
9
const args = Buffer.from (JSON.stringify ([& # x27; start & # x27;, appToken])) .toString (& # x27; base64 & # x27;);
10
await client.execute (& # x27; mobile: startService & # x27;, {
11
intent: & # x27; -- es & quot; args & quot; & quot; & # x27; + args + & # x27; & quot; com.example.appiumcallstestfairy/.TestFairyService & # x27;,
12
});
13
}
14
/**
15
* Sends a string case to currently recorded session. It will show up in the session timeline.
16
* Multiple session that has the same case can be searched at https: //app.testfairy.com/sessions
17
*
18
* @ param guest wdio guest
19
* @ param case Some string value to represent a substantial case hap during tests
20
*/
21
async function addEvent (client, event) {
22
const args = Buffer.from (JSON.stringify ([& # x27; addEvent & # x27;, event])) .toString (& # x27; base64 & # x27;);
23
await client.execute (& # x27; mobile: startService & # x27;, {
24
intention: & # x27; -- es & quot; args & quot; & quot; & # x27; + args + & # x27; & quot; com.example.appiumcallstestfairy/.TestFairyService & # x27;,
25
});
26
}
27
/**
28
* Stops recording a TestFairy session.
29
*
30
* @ param client wdio client
31
*/
32
async office halt (client) {
33
const args = Buffer.from (JSON.stringify ([& # x27; stop & # x27;])) .toString (& # x27; base64 & # x27;);
34
await client.execute (& # x27; mobile: startService & # x27;, {
35
intent: & # x27; -- es & quot; args & quot; & quot; & # x27; + args + & # x27; & quot; com.example.appiumcallstestfairy/.TestFairyService & # x27;,
36
});
37
}
38

Then, invoke TestFairy method wherever you need them.

1
// Test suite
2
describe (& # x27; Create TestFairy session & # x27;, function () {
3
let client;
4
before (async part () {
5
client = await webdriverio.remote (androidOptions);
6
});
7
it (& # x27; should create and destroy a session & # x27;, async function () {
8
const res = await client.status ();
9
assert.isObject (res.build);
10
const current_package = await client.getCurrentPackage ();
11
assert.equal (current_package, & # x27; com.example.appiumcallstestfairy & # x27;);
12
// Start a session
13
console.log (& quot; Starting a TestFairy session & quot;);
14
await begin (client, & quot; SDK-XXXXXXX & quot;); // TestFairy app token can be found at https: //app.testfairy.com/settings
15
// Make your averment
16
// Mark significant points in time during the session to be able to use them later in your TestFairy splashboard for search or preview
17
await addEvent (client, & quot; Initial assertions surpass, this will show up in session timeline & quot;);
18
// Make your affirmation
19
// Stop session
20
await stoppage (client);
21
console.log (& quot; Ending TestFairy session & quot;);
22
const delete_session = await client.deleteSession ();
23
assert.isNull (delete_session);
24
});
25
});
26

What ’ s Inside the TestFairyService?

It is a small service which parses the bundled Intent extra. For simplicity, we pass all arguments as a single twine value, json encode in base64.

1
@Override
2
public int onStartCommand (Intent intent, int masthead, int startId) {
3
Bundle extras = intent.getExtras ();
4
if (extras! = null & amp; & amp; extras.containsKey (& quot; args & quot;)) {
5
try {
6
final String args = extras.getString (& quot; args & quot;);
7
final JSONArray argsArray = new JSONArray (new String (Base64.decode (args, Base64.DEFAULT), StandardCharsets.UTF_8));
8
switch (argsArray.getString (0)) {
9
example & quot; start & quot;:
10
TestFairy.begin (getApplicationContext (), argsArray.getString (1));
11
break;
12
case & quot; addEvent & quot;:
13
TestFairy.addEvent (argsArray.getString (1));
14
break;
15
case & quot; stop & quot;:
16
TestFairy.stop ();
17
break;
18
default:
19
break;
20
}
21
} catch (JSONException t) {
22
Log.w (& quot; TestFairyService & quot;, & quot; Can & # x27; t invoke TestFairy & quot;, t);
23
}
24
}
25
stopSelf ();
26
homecoming super.onStartCommand (purport, flags, startId);
27
}
28

Once the outcry is done, we stop the service so that it does not consume more imagination than necessary.

Win

Here you can chance thecomplete example,include thetest app. Let us know if we can improve it farther. Until so, abide safe and enjoy hacking!

This article was originally issue in August 2021 and has been updated in March 2023.



Diego Perini

Sr. Software Engineer

Published:
Mar 16, 2023
Share this post
Copy Share Link

Want to cognise more? Request a demo today.

DISCOVER

LinkedIn
© 2026 Sauce Labs Inc., all rights allow. SAUCE and SAUCE LABS are registered trademarks own by Sauce Labs Inc. in the United States, EU, and may be registered in early jurisdictions.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free