簡體   English   中英

如何正確使用Python對亞馬遜網絡服務進行自動化測試

[英]How to use Python properly to automation test on amazon web services

我說西班牙語,對不起我的英語。 我有一個移動應用程序,我想使用aws設備農場進行自動化測試。 我在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團隊工作。

  1. 你提到你使用的是Mac。 根據此處的說明如果測試包含非萬向輪,則應使用Linux x86_64機器打包測試。 此外,您還需要確保沒有任何具有本機庫依賴關系的滾輪。

  2. 您應該能夠使用該命令在本地環境中成功檢測測試

    py.test - 僅收集測試/

  3. 您的代碼顯示您正在設置所需的功能。 由於您已經選擇了要在設備場中運行測試的設備和操作系統版本,因此您希望從代碼中刪除所需的功能。 只需要一個空的所需功能對象,該對象將傳遞給驅動程序構造函數。

    desired_caps = {}

  4. 您的驅動程序構造函數需要使用

    wd = webdriver.Remote(' http://127.0.0.1:4723/wd/hub',desired_caps

  5. 截圖代碼必須是

    screenshot_folder = os.getenv('SCREENSHOT_PATH','/ tmp')

  6. 最后確保您的代碼在本地運行,並且在wheelhouse文件夾下沒有任何輪子,根據說明有_MAC_命名依賴項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM