Selenium、appium

selenium




#一個(gè)購物商城的主流程 網(wǎng)址: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()


# 輸入賬號(hào)、密碼、驗(yàn)證碼并點(diǎn)擊登陸按鈕
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()

#點(diǎn)擊首頁按鈕
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()


# 點(diǎn)擊商品進(jìn)入詳情頁
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()

# 點(diǎn)擊確認(rèn)彈窗的×
web.find_element_by_xpath('//*[@id="layui-layer1"]/span/a').click()

# 點(diǎn)擊購物車,進(jìn)入購物車頁面
web.find_element_by_xpath('//*[@id="hd-my-cart"]/a/div/span').click()

# 點(diǎn)擊去結(jié)算按鈕
web.find_element_by_xpath('/html/body/div[4]/div/div/div/div[2]/div[2]/div[1]/a').click()


jump()

# 下拉框不會(huì)寫 閑置  直接點(diǎn)擊提交訂單
# 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()


# 點(diǎn)擊提交訂單按鈕
web.find_element_by_xpath('/html/body/div[14]/div/button').click()






# 生成html的類,單獨(dú)的 和上面的代碼沒有關(guān)系。python+slenium+unittest+htmlTestrunner+excel封裝可以用到這個(gè)類

import unittest
from RequestUnit import RequestUnitTest
from HTMLTestRunner import HTMLTestRunner

class Test():
    def ddd(self):
        print('開始執(zhí)行')
        unit = unittest.TestSuite()
        unit.addTest(RequestUnitTest('test_1'))
        unit.addTest(RequestUnitTest('test_2'))
        with open("./inter.html", "wb") as f:
            HTMLTestRunner(
                stream=f,
                title="單元測(cè)試",
                description="測(cè)試一期",
                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'  #安卓版本號(hào)
desired_caps['deviceName'] = '127.0.0.1:5554'
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'  #自動(dòng)進(jìn)入的頁面
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True



driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
print(driver)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容