如何正确使用 Python 对亚马逊网络服务进行自动化测试
How to use Python properly to automation test on amazon web services
我说西班牙语,对不起我的英语。我有一个移动应用程序,我想使用 aws device farm 进行自动化测试。我正在使用 Mac,我正在尝试对我的 Android 应用程序进行简单测试:点击登录按钮,输入用户名和密码,然后登录。
我正在使用 appium 为我的测试提供一个 python 代码,然后我将我的 .apk 和一个 zip 文件与我的测试一起上传到 aws,但它总是失败。我是 python 的新手,找不到对我有帮助的示例。
我按照 http://docs.aws.amazon.com/es_es/devicefarm/latest/developerguide/test-types-android-appium-python.html 上的所有步骤进行操作,但是 运行 测试给出的只是失败并且没有截屏。
这是.py代码:
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains
import time
import os.path
import unittest
from selenium import webdriver
success = True
desired_caps = {}
desired_caps['appium-version'] = '1.0'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.0.1'
desired_caps['app'] = os.path.abspath('/Users/developer/Documents/AWS/workspace/APK/Squeeze.apk')
desired_caps['appPackage'] = 'com.example.mkim.aut'
desired_caps['appActivity'] = 'com.example.mkim.aut.SuccessfulLogin'
wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
wd.implicitly_wait(60)
screenshot_folder = os.getenv('SCREENSHOT_PATH', '')
wd.save_screenshot(screenshot_folder + "/screenshot.png")
def is_alert_present(wd):
try:
wd.switch_to_alert().text
return True
except:
return False
try:
#self.driver.save_screenshot(screenshot_folder + "/screenshot.png")
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": 666, "y": 1519 })
wd.save_screenshot(screenshot_folder + "/screenshot1.png")
wd.find_element_by_xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.webkit.WebView[1]/android.webkit.WebView[1]/android.view.View[1]/android.view.View[1]").click()
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": 121, "y": 726 })
wd.find_element_by_name("(null)").send_keys("Squeeze@mailinator.com")
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": 191, "y": 919 })
wd.find_element_by_name("(null)").send_keys("Password")
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": 563, "y": 1079 })
except:
wd.quit()
if not success:
raise Exception("Test failed.")
我在 AWS Device farm 团队工作。
您提到您正在使用 Mac。根据说明 here,您应该使用 Linux x86_64 机器来打包您的测试,如果它包含一个非通用轮。此外,您还需要确保没有任何具有本机库依赖项的轮子。
您应该能够使用命令
在您的本地环境中成功检测您的测试
py.test -- 仅收集测试/
您的代码表明您正在设置所需的功能。由于您已经选择了要在设备场中 运行 测试的设备和 OS 版本,因此您希望从代码中删除那些所需的功能。只需将一个空的所需功能对象传递给驱动程序构造函数即可。
desired_caps = {}
您的驱动程序构造函数需要使用
wd = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
截图代码必须是
screenshot_folder = os.getenv('SCREENSHOT_PATH', '/tmp')
最后确保你的代码 运行s 在本地并且你在 wheelhouse 文件夹下没有任何 wheels,其中有 _MAC_ 命名为依赖项按照说明。
我说西班牙语,对不起我的英语。我有一个移动应用程序,我想使用 aws device farm 进行自动化测试。我正在使用 Mac,我正在尝试对我的 Android 应用程序进行简单测试:点击登录按钮,输入用户名和密码,然后登录。 我正在使用 appium 为我的测试提供一个 python 代码,然后我将我的 .apk 和一个 zip 文件与我的测试一起上传到 aws,但它总是失败。我是 python 的新手,找不到对我有帮助的示例。
我按照 http://docs.aws.amazon.com/es_es/devicefarm/latest/developerguide/test-types-android-appium-python.html 上的所有步骤进行操作,但是 运行 测试给出的只是失败并且没有截屏。
这是.py代码:
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains
import time
import os.path
import unittest
from selenium import webdriver
success = True
desired_caps = {}
desired_caps['appium-version'] = '1.0'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.0.1'
desired_caps['app'] = os.path.abspath('/Users/developer/Documents/AWS/workspace/APK/Squeeze.apk')
desired_caps['appPackage'] = 'com.example.mkim.aut'
desired_caps['appActivity'] = 'com.example.mkim.aut.SuccessfulLogin'
wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
wd.implicitly_wait(60)
screenshot_folder = os.getenv('SCREENSHOT_PATH', '')
wd.save_screenshot(screenshot_folder + "/screenshot.png")
def is_alert_present(wd):
try:
wd.switch_to_alert().text
return True
except:
return False
try:
#self.driver.save_screenshot(screenshot_folder + "/screenshot.png")
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": 666, "y": 1519 })
wd.save_screenshot(screenshot_folder + "/screenshot1.png")
wd.find_element_by_xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.webkit.WebView[1]/android.webkit.WebView[1]/android.view.View[1]/android.view.View[1]").click()
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": 121, "y": 726 })
wd.find_element_by_name("(null)").send_keys("Squeeze@mailinator.com")
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": 191, "y": 919 })
wd.find_element_by_name("(null)").send_keys("Password")
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": 563, "y": 1079 })
except:
wd.quit()
if not success:
raise Exception("Test failed.")
我在 AWS Device farm 团队工作。
您提到您正在使用 Mac。根据说明 here,您应该使用 Linux x86_64 机器来打包您的测试,如果它包含一个非通用轮。此外,您还需要确保没有任何具有本机库依赖项的轮子。
您应该能够使用命令
在您的本地环境中成功检测您的测试py.test -- 仅收集测试/
您的代码表明您正在设置所需的功能。由于您已经选择了要在设备场中 运行 测试的设备和 OS 版本,因此您希望从代码中删除那些所需的功能。只需将一个空的所需功能对象传递给驱动程序构造函数即可。
desired_caps = {}
您的驱动程序构造函数需要使用
wd = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
截图代码必须是
screenshot_folder = os.getenv('SCREENSHOT_PATH', '/tmp')
最后确保你的代码 运行s 在本地并且你在 wheelhouse 文件夹下没有任何 wheels,其中有 _MAC_ 命名为依赖项按照说明。