Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

add android script runner into IATF. #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 31 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ In this section, we present our design to address the aforementioned problems vi
+ Intermediate communication component between test server and test devices
3. **Test Client**: The test clients are the SUT (system under testing) on which the test cases with corresponding third-party API test framework are executed. They are deployed on top of different platforms for different types of API testing.

## Sample with JavaScript client

A sample is included to demostrate how to add and run a task for two web endpoints. Task info will be uploaded by a REST request, and both test devices will be launched by controller and WebDriver.

1. Install dependence and start IATF server.
Expand All @@ -67,7 +65,7 @@ A sample is included to demostrate how to add and run a task for two web endpoin
```
node src/server/server.js --certificate_file <cert> --key_file <key>
```

## Sample with JavaScript client
2. Host test pages.

As current sample is a html page, you'll need a web server to host it and its resources. If you don't have such a web server, http-server might be a choice for development or evaluation. Simplely install it by `npm install -g http-server`. Then `http-server src\client`. It will listen HTTP request on 8081 port because the default 8080 is occupied by IATF server.
Expand All @@ -91,7 +89,36 @@ As current sample is a html page, you'll need a web server to host it and its re
+ Install webdriver,download the corresponding webdrivers for your tested browser.
+ Modify webdriver installation path in src/controller/runners/javascriptrunner.py.

## Sample with Android client
2. Install your test apk to android device
3. Add a task to IATF server by a REST request (PUT) to `https://<server>/rest/v1/tasks`. An example could be
```
{
"roles": [{
"name": "role1",
"type": "Android",
"config": {
"sourcePath": "your_source_path",
"package": "package_name",
"testClass": "test_class",
"testRunner": "android.support.test.runner.AndroidJUnitRunner",
"device": "android_device"
}
},{
"name": "role2",
"type": "Android",
"config": {
"sourcePath": "your_source_path",
"package": "package_name",
"testClass": "test_class",
"testRunner": "android.support.test.runner.AndroidJUnitRunner",
"device": "android_device"
}
}]
}
```
5. Start client controller.
```
python src/controller/controller.py --server https://localhost:8080 --no_ssl_verification --task <taskId>
```
```

41 changes: 41 additions & 0 deletions src/controller/runners/androidscriptrunner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import subprocess
import os
import sys
from runner import Runner


class AndroidRuner(Runner):
def __init__(self, context):
self.source_path = context.config.get('sourcePath', None)
self.test_class = context.config.get('testClass', None)
self.device = context.config.get('device', None)
self.task_id = context.task_id
self.role = context.role
self.package = context.config.get('package', None)
self.test_runner = context.config.get('testRunner', None)

def setup(self):
pass

def teardown(self):
pass

def run(self):
if not os.path.exists(self.source_path):
print('Error android source path.')
return

t_class = self.package + '.' + self.test_class

self.test_runner = 'android.support.test.runner.AndroidJUnitRunner' if self.test_runner is None else self.test_runner

cmd = ['adb', '-s', self.device, 'shell', 'am', 'instrument', '-w', '-r', '-e', 'taskId', self.task_id, '-e',
'class', t_class, self.package + '.test/' + self.test_runner]

with open(os.path.join(self.source_path, self.device+".log"), 'w') as f:
proc = subprocess.Popen(cmd, cwd=self.source_path, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in proc.stdout:
line = line.decode("utf-8")
sys.stdout.write(line)
f.write(line)
proc.communicate()