Run E2E Tests only if needed

This commit is contained in:
butomo1989 2017-06-02 13:18:00 +02:00
parent aff1b062e1
commit dcf196ec4a
2 changed files with 45 additions and 11 deletions

View file

@ -102,23 +102,21 @@ function test() {
test_image=test_img test_image=test_img
test_container=test_con test_container=test_con
# Run unit test # Run e2e tests
echo "----UNIT TEST----" # E2E tests must be run only for linux OS / x86 image to reduce duration of test execution
(export ANDROID_HOME=/root && export ANDROID_VERSION=$test_android_version && export API_LEVEL=$test_api_level \ if [ "$(uname -s)" == 'Linux' ] && [ "$E2E" = true ]; then
&& export PROCESSOR=$test_processor && export SYS_IMG=$test_sys_img && export IMG_TYPE=$test_img_type \
&& nosetests src/tests/unit -v)
# Run integration test
# Integration test must be run only for linux OS / x86 image to reduce duration of test execution
if [ "$(uname -s)" == 'Linux' ]; then
echo "----BUILD TEST IMAGE----" echo "----BUILD TEST IMAGE----"
docker build -t $test_image --build-arg ANDROID_VERSION=$test_android_version \ docker build -t $test_image --build-arg ANDROID_VERSION=$test_android_version \
--build-arg BUILD_TOOL=$LATEST_BUILD_TOOL --build-arg API_LEVEL=$test_api_level \ --build-arg BUILD_TOOL=$LATEST_BUILD_TOOL --build-arg API_LEVEL=$test_api_level \
--build-arg PROCESSOR=$test_processor --build-arg SYS_IMG=$test_sys_img \ --build-arg PROCESSOR=$test_processor --build-arg SYS_IMG=$test_sys_img \
--build-arg IMG_TYPE=$test_img_type -f docker/Emulator_x86 . --build-arg IMG_TYPE=$test_img_type -f docker/Emulator_x86 .
echo "----RUN E2E TEST----" echo "----REMOVE OLD TEST CONTAINER----"
docker run --privileged -d -p 4723:4723 -p 6080:6080 -e APPIUM=True --name $test_container $test_image docker kill $test_container && docker rm $test_container
echo "----PREPARE CONTAINER----"
docker run --privileged -d -p 4723:4723 -p 6080:6080 -e APPIUM=True -e DEVICE="Samsung Galaxy S6" --name $test_container $test_image
docker cp example/sample_apk $test_container:/root/tmp
attempt=0 attempt=0
while [ ${attempt} -le 10 ]; do while [ ${attempt} -le 10 ]; do
attempt=$(($attempt + 1)) attempt=$(($attempt + 1))
@ -137,11 +135,18 @@ function test() {
fi fi
done done
echo "----RUN E2E TESTS----"
nosetests src/tests/e2e -v nosetests src/tests/e2e -v
echo "----REMOVE TEST CONTAINER----" echo "----REMOVE TEST CONTAINER----"
docker kill $test_container && docker rm $test_container docker kill $test_container && docker rm $test_container
fi fi
# Run unit tests (After e2e test to get coverage result)
echo "----UNIT TESTS----"
(export ANDROID_HOME=/root && export ANDROID_VERSION=$test_android_version && export API_LEVEL=$test_api_level \
&& export PROCESSOR=$test_processor && export SYS_IMG=$test_sys_img && export IMG_TYPE=$test_img_type \
&& nosetests src/tests/unit -v)
} }
function build() { function build() {

View file

@ -0,0 +1,29 @@
"""e2e test to test sample android application inside docker-android"""
from unittest import TestCase
from appium import webdriver
class TestE2EApp(TestCase):
def setUp(self):
desired_caps = {
'platformName': 'Android',
'deviceName': 'Android Emulator',
'automationName': 'UIAutomator2',
'app': '/root/tmp/sample_apk_debug.apk'
}
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def test_calculation(self):
text_fields = self.driver.find_elements_by_class_name('android.widget.EditText')
text_fields[0].send_keys(4)
text_fields[1].send_keys(6)
btn_calculate = self.driver.find_element_by_class_name('android.widget.Button')
btn_calculate.click()
self.assertEqual('10', text_fields[2].text)
def tearDown(self):
self.driver.quit()