Last active
June 27, 2019 11:22
-
-
Save vinaysshenoy/1064d8d63277eb37028725ed6182e36d to your computer and use it in GitHub Desktop.
Run UI tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prerequisites | |
# - Python 3 | |
# - *nix OS | |
# - git must be available on the command line | |
# - Android SDK and Java 8 must be setup | |
# - Repository SSH fingerptint must be added to ~/.ssh/known_hosts | |
# - ANDROID_SDK_ROOT env variable must be set | |
# - An AVD with the name "uitest" must be pre-created | |
# - mongodb started and running on port 27017 | |
import os | |
import shutil | |
uiTestRepository = "[email protected]:simpledotorg/simple-android-ui-tests.git" | |
appToTestRepository = "[email protected]:simpledotorg/simple-android.git" | |
def sourceDirectoryFromGitUrl(repositoryUrl): | |
return repositoryUrl[repositoryUrl.rfind('/') + 1:repositoryUrl.rfind('.git')] | |
uiTestDirectory = sourceDirectoryFromGitUrl(uiTestRepository) | |
appToTestDirectory = sourceDirectoryFromGitUrl(appToTestRepository) | |
def deleteDirectoryIfExists(directory): | |
if(os.path.exists(directory)): | |
shutil.rmtree(directory) | |
deleteDirectoryIfExists(uiTestDirectory) | |
deleteDirectoryIfExists(appToTestDirectory) | |
def clone(repositoryUrl): | |
print('Clone {}'.format(repositoryUrl)) | |
cmd = 'git clone -b master --single-branch --depth 1 {}'.format(repositoryUrl) | |
status = os.system(cmd) | |
if(status != 0): | |
print('Could not clone {}'.format(repositoryUrl)) | |
quit() | |
def buildAppToTest(): | |
srcDir = appToTestDirectory | |
print('Build {}'.format(srcDir)) | |
cmd = '{0}/gradlew -p {0} app:assembleQaDebug'.format(srcDir) | |
status = os.system(cmd) | |
if(status != 0): | |
print('Could not build {}'.format(srcDir)) | |
quit() | |
def copyApkToTestDir(): | |
srcPath = os.path.join(appToTestDirectory, 'app', 'build', 'outputs', 'apk', 'qa', 'debug', 'app-qa-debug.apk') | |
os.makedirs(name = os.path.join(uiTestDirectory, 'app'), exist_ok = True) | |
dstPath = os.path.join(uiTestDirectory, 'app', 'qaDebug.apk') | |
print('Copy {} to {}'.format(srcPath, dstPath)) | |
shutil.copyfile(srcPath, dstPath) | |
clone(uiTestRepository) | |
clone(appToTestRepository) | |
buildAppToTest() | |
copyApkToTestDir() | |
def launchEmulator(avd): | |
print('Launch {}'.format(avd)) | |
# The emulator command seems to have some issues with relative paths so we need to change the | |
# working directory to the sdk tools directory and then run the emulator command. | |
# | |
# We also need to add an '&' at the end after starting the emulator because otherwise | |
# the emulator command would never return. | |
cmd = 'cd $ANDROID_SDK_ROOT/tools && ./emulator -avd {} &'.format(avd) | |
status = os.system(cmd) | |
if(status != 0): | |
print('Could not launch {}'.format(avd)) | |
quit() | |
launchEmulator('uitest') | |
def runUiTests(testDir): | |
cmd = '{0}/gradlew -p {0} runDistribution -DtestFeed=simple -Dtags=@overdue1'.format(testDir) | |
status = os.system(cmd) | |
if(status != 0): | |
print('Could not run UI tests') | |
quit() | |
runUiTests(uiTestDirectory) | |
change simple.json paths of node and appium | |
# deleteDirectoryIfExists(uiTestDirectory) | |
# deleteDirectoryIfExists(appToTestDirectory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment