unittest 加载case

1、执行所有case if __name__==’__main__’: unittest.main() 2、通过testsuit来执行case if __name__ == ‘__main__’: #构造测试集 suite = unittest.TestSuite() suite.addTest(测试类(’case名称’)) #执行测试 runner = unittest.TextTestRunner(verbosity=3) runner.run(suite) 3、跳过某一个case 在case前增加@skip 来跳过case

appium 碰到的坑

1、failed install setting_apk-debug.apk 解决办法: 找到android.js 找到下面代码: async.series([ this.initJavaVersion.bind(this), this.initAdb.bind(this), this.packageAndLaunchActivityFromManifest.bind(this), this.initUiautomator.bind(this), this.prepareDevice.bind(this), this.checkApiLevel.bind(this), this.pushStrings.bind(this), this.processFromManifest.bind(this), this.uninstallApp.bind(this), this.installAppForTest.bind(this), this.forwardPort.bind(this), this.pushAppium.bind(this), this.initUnicode.bind(this), // this.pushSettingsApp.bind(this), //this.pushUnlock.bind(this), function (cb) {this.uiautomator.start(cb);}.bind(this), this.wakeUp.bind(this), this.unlock.bind(this), this.getDataDir.bind(this), 注释掉: this.pushSettingsApp.bind(this), this.pushUnlock.bind(this), 2、连接真机报command failed shell “ps ‘uiautomator错误 文件路径为:/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib 找到一下代码: ADB.prototype.shell = function (cmd, cb) { if (cmd.indexOf(‘”‘) === -1) { cmd = ‘”‘ + cmd…

senlenium send.key批量输入

#coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.get("http://192.168.1.17:8090/login") time.sleep(3) driver.find_element_by_id("amount").send_keys("输入你的账号") driver.find_element_by_id("password").send_keys("输入你的密码") driver.find_element_by_xpath("/html/body/section/div/div[2]/div/form/input").click() time.sleep(5) a= 0 while a<=3:     connect = ["test1","hi",u"地方","dhf"]     for i in connect:         driver.find_element_by_xpath("/html/body/header/div/div[1]/ul/li[3]").click()         time.sleep(5)         driver.find_element_by_class_name("add-shop").click()         time.sleep(3)        …

selenium 获取登录cookie

#coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.get("http://192.168.1.17:8090/login") time.sleep(3) driver.find_element_by_id("amount").send_keys("173") driver.find_element_by_id("password").send_keys("123") driver.find_element_by_xpath("/html/body/section/div/div[2]/div/form/input").click() time.sleep(5) cookie = driver.get_cookies() cookie_list = [] for i in cookie:     cookie = i[’name’] + ‘=’ + i[’value’]     cookie_list.append(cookie) cookie_str = ";".join(cookie_list) print cookie_str driver.quit()

selenium 登录Demo

#coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.get(“http://192.168.1.17:8090/login”) time.sleep(3) driver.find_element_by_id(“amount”).send_keys(“173”) driver.find_element_by_id(“password”).send_keys(“123”) driver.find_element_by_xpath(“/html/body/section/div/div[2]/div/form/input”).click() time.sleep(4) driver.quit()

selenium web页面滚动滚动条

#coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.set_page_load_timeout(10) driver.get(‘https://www.baidu.com/’) driver.maximize_window() driver.find_element_by_id(“kw”).send_keys(“selenium”) driver.find_element_by_id(“su”).click() time.sleep(3) js = “var c=document.body.scrollTop=100000” driver.execute_script(js) time.sleep(6) driver.quit() 第二种: #coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.set_page_load_timeout(10) driver.get(‘https://www.baidu.com/’) driver.maximize_window() driver.find_element_by_id(“kw”).send_keys(“selenium”) driver.find_element_by_id(“su”).click() time.sleep(3) driver.execute_script(“window.scrollTo(0,100000)”) time.sleep(6) driver.quit()

selenium 网页搜索Demo

#coding=utf-8 from selenium import webdriver from selenium.webdriver.common.keys import Keys import unittest class PythonSearch(unittest.TestCase): def setUp(self): self.driver = webdriver.Safari() def test_search(self): driver = self.driver driver.get(“http://www.python.org”) elem = driver.find_element_by_name(“q”) elem.send_keys(“pyhton”) elem.send_keys(Keys.RETURN) assert “No results found.” not in driver.page_source def tearDown(self): self.driver.quit() if __name__ == “__main__”: unittest.main()