You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
5.8 KiB
154 lines
5.8 KiB
import unittest |
|
|
|
# Import time module to implement |
|
import time |
|
|
|
# Import the Selenium 2 module (aka "webdriver") |
|
from selenium import webdriver |
|
|
|
# For automating data input |
|
from selenium.webdriver.common.keys import Keys |
|
|
|
# For providing custom configurations for Chrome to run |
|
from selenium.webdriver.chrome.options import Options |
|
|
|
|
|
# class PythonOrgSearchChrome(unittest.TestCase): |
|
|
|
def iphone_options(): |
|
mobile_emulation = { |
|
#"deviceName": "Apple iPhone 3GS" |
|
#"deviceName": "Apple iPhone 4" |
|
"deviceName": "Apple iPhone X" |
|
#"deviceName": "Apple iPhone 5" |
|
#"deviceName": "Apple iPhone 6" |
|
#"deviceName": "Apple iPhone 6 Plus" |
|
#"deviceName": "Apple iPad 1 / 2 / iPad Mini" |
|
#"deviceName": "Apple iPad 3 / 4" |
|
|
|
|
|
# Or specify a specific build using the following two arguments |
|
#"deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 }, |
|
#"userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" } |
|
} |
|
|
|
options = webdriver.ChromeOptions() |
|
options.add_experimental_option("mobileEmulation", mobile_emulation) |
|
# options = Options() |
|
# options.add_argument("--start-maximized") |
|
# options.add_argument("--ignore-certificate-errors") |
|
# options.add_argument("--no-sandbox") |
|
# options.add_argument("--disable-extensions") |
|
# # Disable webdriver flags or you will be easily detectable |
|
# options.add_argument("--disable-blink-features") |
|
# options.add_argument("--disable-blink-features=AutomationControlled") |
|
# extras |
|
# Select which device you want to emulate by uncommenting it |
|
# More information at: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation |
|
|
|
return options |
|
|
|
|
|
def iphone_capabilities(session_id): |
|
PROXY = "192.168.1.101:8889" |
|
capabilities = { |
|
"browserName": "chrome", |
|
"browserVersion": "latest", |
|
"pageLoadStrategy": "normal", |
|
"javascriptEnabled": True, |
|
"selenoid:options": { |
|
"enableVNC": True, |
|
"enableVideo": True, |
|
"enableLog": True, |
|
"videoName": f"{session_id}.mp4", |
|
"logName": f"{session_id}.log", |
|
"name": session_id, |
|
# "sessionTimeout": "30m" |
|
}, |
|
"proxy": { |
|
"httpProxy": PROXY, |
|
"ftpProxy": PROXY, |
|
"sslProxy": PROXY, |
|
"proxyType": "MANUAL", |
|
"autodetect": False, |
|
}, |
|
"loggingPrefs": { |
|
"driver": "FINE", |
|
"server": "FINE", |
|
"browser": "FINE", |
|
}, |
|
} |
|
return capabilities |
|
# Anything declared in setUp will be executed for all test cases |
|
# def setUp(self): |
|
# # Select which device you want to emulate by uncommenting it |
|
# # More information at: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation |
|
# mobile_emulation = { |
|
# #"deviceName": "Apple iPhone 3GS" |
|
# #"deviceName": "Apple iPhone 4" |
|
# "deviceName": "Apple iPhone X" |
|
# #"deviceName": "Apple iPhone 5" |
|
# #"deviceName": "Apple iPhone 6" |
|
# #"deviceName": "Apple iPhone 6 Plus" |
|
# #"deviceName": "Apple iPad 1 / 2 / iPad Mini" |
|
# #"deviceName": "Apple iPad 3 / 4" |
|
|
|
|
|
# # Or specify a specific build using the following two arguments |
|
# #"deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 }, |
|
# #"userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" } |
|
# } |
|
|
|
# # Define a variable to hold all the configurations we want |
|
# chrome_options = webdriver.ChromeOptions() |
|
|
|
# # Add the mobile emulation to the chrome options variable |
|
# chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) |
|
|
|
# # Create driver, pass it the path to the chromedriver file and the special configurations you want to run |
|
# self.driver = webdriver.Chrome(executable_path='/Library/Python/2.7/site-packages/selenium/webdriver/chrome/chromedriver', chrome_options=chrome_options) |
|
|
|
# An individual test case. Must start with 'test_' (as per unittest module) |
|
# def test_search_in_python_chrome(self): |
|
# # Assigning a local variable for the global driver |
|
# driver = self.driver |
|
|
|
# # Go to google.com |
|
# driver.get('http://www.google.com') |
|
|
|
# # A test to ensure the page has keyword Google in the page title |
|
# self.assertIn("Google", driver.title) |
|
|
|
# # Pauses the screen for 5 seconds so we have time to confirm it arrived at the right page |
|
# time.sleep(5) |
|
|
|
# # Find and select the search box element on the page |
|
# search_box = driver.find_element_by_name('q') |
|
|
|
# # Enter text into the search box |
|
# search_box.send_keys('Devin Mancuso') |
|
|
|
# # Make sure the results page returned something |
|
# assert "No results found." not in driver.page_source |
|
|
|
# # Submit the search box form |
|
# search_box.submit() |
|
|
|
# # Can also use Keys function to submit |
|
# #search_box.send_keys(Keys.RETURN) |
|
|
|
# # Another pause so we can see what's going on |
|
# time.sleep(5) |
|
|
|
# # Take a screenshot of the results |
|
# driver.save_screenshot('screenshot-deskto-chrome.png') |
|
|
|
# # Anything declared in tearDown will be executed for all test cases |
|
# def tearDown(self): |
|
# # Close the browser. |
|
# # Note close() will close the current tab, if its the last tab it will close the browser. To close the browser entirely use quit() |
|
# self.driver.close() |
|
|
|
# # Boilerplate code to start the unit tests |
|
# if __name__ == "__main__": |
|
# unittest.main()
|
|
|