尝试方法 -在众多平台快速通过脚本自动化验证页面兼容性,可以验证pc,web ,android ,ios,驱动支持java,ruby,c#,python ,js

#test_baidu.py
import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys


class LTAutomate(unittest.TestCase):


def setUp(self):


# username: Username can be found at automation dashboard
username = "2677989813@qq.com"
accessToken = "PNyq3u1hemsDqX8WEgSA9uxSVusNVD02aoUV1anK9sLJtdCdtI"
gridUrl = "hub.lambdatest.com/wd/hub"

desired_cap = {

'platform':"Windows 10",
'browserName': "chrome",
'version': "67.0",
# Resolution of machine
"resolution": "1024x768",
"name": "name is baidu ",
"build": "test_build",
"network": True,
"video": True,
"visual": True,
"console": True,
}

# URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub
url = "https://" + username + ":" + accessToken + "@" + gridUrl

# print("Initiating remote driver on platfrom: " + desired_cap["platform"] + " browser: " + desired_cap[
# "browserName"] + " version: " + desired_cap["version"])
self.driver = webdriver.Remote(
desired_capabilities=desired_cap,
command_executor=url
)

def test_search_in_baidu(self):

driver = self.driver

driver.get("https://www.baidu.com/")


time.sleep(4)
elem = driver.find_element_by_id("kw")
time.sleep(3)
elem.send_keys("123")
time.sleep(3)
click_test=driver.find_element_by_id('su').click()
time.sleep(2)


driver.execute_script("lambda-status=passed")

def tearDown(self):

self.driver.quit()


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

#run python -m unittest test_baidu.py

效果图:

 

 

 

#配置caps 运行多个

import time
import os
from threading import Thread
from selenium import webdriver

def get_browser(caps):
return webdriver.Remote(
command_executor="https://:@hub.lambdatest.com/wd/hub".format("你的账号", "你的key"),
desired_capabilities=caps
)

browsers = [
{"build": 'test-1',"name": "Test 1", "platform": "Windows 10","browserName": "Chrome", "version": "95"},
{"build": 'test-2',"name": "Test 3", "platform": "MacOS Catalina","browserName": "Chrome", "version": "95"},
{"build": 'test-3',"name": "Test 4", "platform": "Windows 7","browserName": "Chrome", "version": "92"}

]
browsers_waiting = []

def get_browser_and_wait(browser_data):
# print ("starting %s" % browser_data["name"])
browser = get_browser(browser_data)
browser.get("https://www.baidu.com")

time.sleep(4)
elem = browser.find_element_by_id("kw")
time.sleep(3)
elem.send_keys("123")
time.sleep(3)
click_test = browser.find_element_by_id('su').click()
time.sleep(2)

browsers_waiting.append({"data": browser_data, "driver": browser})
while len(browsers_waiting) < len(browsers):
	browser.get("https://www.baidu.com")
	time.sleep(3)

thread_list = []
for i, browser in enumerate(browsers):
t = Thread(target=get_browser_and_wait, args=[browser])
thread_list.append(t)
t.start()

for t in thread_list:
t.join()

for i, b in enumerate(browsers_waiting):
b["driver"].quit()

posted @ 2021-11-18 16:46  yanhuidj  阅读(42)  评论(0编辑  收藏  举报