selenium
#一个购物商城的主流程 网址:http://www.testingedu.com.cn:8000/index.php/home/User/login.html
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
# 切换页面
def jump():
handles = web.window_handles
web.switch_to_window(handles[handles.__len__() - 1])
time.sleep(4)
web = webdriver.Chrome()
web.get('http://www.testingedu.com.cn:8000/index.php/home/User/login.html')
web.maximize_window()
# 输入账号、密码、验证码并点击登陆按钮
userName = web.find_element_by_id('username')
userName.send_keys('13800138006')
pwd = web.find_element_by_id('password')
pwd.send_keys('123456')
login_code = web.find_element_by_id('verify_code')
login_code.send_keys('1234')
web.find_element_by_xpath('//*[@id="loginform"]/div/div[6]/a').click()
jump()
#点击首页按钮
web.find_element_by_xpath('/html/body/div[2]/div/div[3]/ul/li[1]/a').click()
jump()
phone = web.find_element_by_xpath('//*[@id="cata-nav"]/div[1]/div[1]/h3/div/a')
ActionChains(web).move_to_element(phone).perform()
web.find_element_by_xpath('//*[@id="cata-nav"]/div[1]/div[2]/div[1]/div[2]/dl[1]/dd/a[1]').click()
jump()
# 点击商品进入详情页
web.find_element_by_xpath('//*[@id="ajax_hot_goods"]/div[1]/a/img').click()
jump()
# 加入购物车
web.find_element_by_xpath('//*[@id="join_cart"]').click()
jump()
# 点击确认弹窗的×
web.find_element_by_xpath('//*[@id="layui-layer1"]/span/a').click()
# 点击购物车,进入购物车页面
web.find_element_by_xpath('//*[@id="hd-my-cart"]/a/div/span').click()
# 点击去结算按钮
web.find_element_by_xpath('/html/body/div[4]/div/div/div/div[2]/div[2]/div[1]/a').click()
jump()
# 下拉框不会写 闲置 直接点击提交订单
# web.find_element_by_id('addNewAddress').click()
# jump()
# web.find_element_by_xpath('//*[@id="address_form"]/div[2]/div/div[2]/div[1]/div/input').send_keys('若星')
# web.find_element_by_xpath('//*[@id="address_form"]/div[2]/div/div[2]/div[2]/div/input').send_keys('15138523113')
# web.find_element_by_id('province')
# web.find_element_by_name('province')[1].click()
# web.find_element_by_id('city')
# web.find_element_by_name('city')[1].click()
# web.find_element_by_xpath('//*[@id="address_form"]/div[2]/div/div[2]/div[4]/div/input').send_keys('青旅教育基地')
# web.find_element_by_xpath('//*[@id="address_form"]/div[2]/div/div[2]/div[5]/div/input').send_keys('102200')
# web.find_element_by_id('address_submit').click()
# 点击提交订单按钮
web.find_element_by_xpath('/html/body/div[14]/div/button').click()
# 生成html的类,单独的 和上面的代码没有关系。python+slenium+unittest+htmlTestrunner+excel封装可以用到这个类
import unittest
from RequestUnit import RequestUnitTest
from HTMLTestRunner import HTMLTestRunner
class Test():
def ddd(self):
print('开始执行')
unit = unittest.TestSuite()
unit.addTest(RequestUnitTest('test_1'))
unit.addTest(RequestUnitTest('test_2'))
with open("./inter.html", "wb") as f:
HTMLTestRunner(
stream=f,
title="单元测试",
description="测试一期",
verbosity=2
).run(unit)
t = Test()
t.ddd()
appium
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.1' #安卓版本号
desired_caps['deviceName'] = '127.0.0.1:5554'
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings' #自动进入的页面
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
print(driver)