selendroid testing android web APP notes

1. 参考http://www.guru99.com/introduction-to-selendroid.html


2. 使用下面的网址查看真机是否连接上,
http://localhost:4444/wd/hub/status

{
  "status": 0,
  "value": {
    "supportedApps": [
      {
        "appId": "io.selendroid.androiddriver:0.17.0",
        "mainActivity": "io.selendroid.androiddriver.WebViewActivity",
        "basePackage": "io.selendroid.androiddriver"
      }
    ],
    "os": {
      "arch": "amd64",
      "name": "Windows 7",
      "version": "6.1"
    },
    "build": {
      "browserName": "selendroid",
      "version": "0.17.0"
    },
    "supportedDevices": [
      {
        "screenSize": "(1080, 1920)",
        "platformVersion": "22",
        "model": "m2 note",
        "emulator": false,
        "apiTargetType": "google",
        "serial": "81UEBM726HHK"
      }
    ]
  }
}


3. 测试程序 baidu.py, 模拟在手机里面打开浏览器,使用baidu搜索,程序是使用selenium IDE导出的

#!/usr/bin/python
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class Baidu(unittest.TestCase):
    def setUp(self):
        desired_capabilities = {'emulator':False, 'platform': 'ANDROID', 'browserName': 'android', 'version': '', 'javascriptEnabled': True}
        self.driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.ANDROID)
        #self.driver = webdriver.Remote(desired_capabilities=desired_capabilities)
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.baidu.com/"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    def test_baidu(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("kw").clear()
        driver.find_element_by_id("kw").send_keys("selendroid")
        driver.find_element_by_id("su").click()
        time.sleep(30)
    
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True
    
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
    
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()


4. 使用eclipse,在eclipse里面运行测试脚本没有问题,但是单独运行测试脚本,baidu.py,显示 KeyError: 'sessionId'
selendroid testing android web APP notes_第1张图片



5. 使用http://localhost:4444/inspector/,可以进行debug

你可能感兴趣的:(selendroid)