diff --git a/readme.md b/readme.md index 3e6be8d..51882ac 100644 --- a/readme.md +++ b/readme.md @@ -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. @@ -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 --key_file ``` - +## 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. @@ -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:///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 -``` \ No newline at end of file +``` + diff --git a/src/controller/runners/androidscriptrunner.py b/src/controller/runners/androidscriptrunner.py new file mode 100644 index 0000000..eea313c --- /dev/null +++ b/src/controller/runners/androidscriptrunner.py @@ -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()