Java:
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.3");
desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
desiredCapabilities.setCapability(MobileCapabilityType.APP, "/path/to/ios/app.zip");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
IOSDriver driver = new IOSDriver(url, desiredCapabilities);
String sessionId = driver.getSessionId().toString();
Python:
desired_caps = desired_caps = {
'platformName': 'Android',
'platformVersion': '7.0',
'deviceName': 'Android Emulator',
'automationName': 'UiAutomator2',
'app': PATH('/path/to/app')
}
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
Description
The server should attempt to create a session that most closely matches the desired and required capabilities.
JSONWP Spec Required capabilities have higher priority than desired capabilities and must be set for the session to be created W3C Spec capabilities.alwaysMatch must be set for session to be created; capabilities.firstMatch must match at least one (the first one to match will be used)
Java:driver.quit();
Python:self.driver.quit()
Retrieve the capabilities of the specified session
Java:Map<String, Object> caps = driver.getSessionDetails();
Python:desired_caps = self.driver.desired_capabilities()
Navigate backwards in the browser history, if possible (Web context only)
Java:driver.back();
Python:self.driver.back()
Take a screenshot of the current viewport/window/page
Java:File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
Python:screenshotBase64 = self.driver.get_screenshot_as_base64()
Get the current application hierarchy XML (app) or page source (web)
Java:String pageSource = driver.getPageSource();
Python:source = self.driver.page_source
Configure the amount of time that a particular type of operation can execute for before they are aborted
Java:driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
Python:self.driver.set_page_load_timeout(5000)
Set the amount of time the driver should wait when searching for elements
Java:driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Python:self.driver.implicitly_wait(5000)
Set the amount of time, in milliseconds, that asynchronous scripts executed by execute async are permitted to run before they are aborted (Web context only)
Java:driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
Python:self.driver.set_script_timeout(5000)
Get the current device/browser orientation
Java:ScreenOrientation orientation = driver.getOrientation();
Python:orientation = self.driver.orientation()
Set the current device/browser orientation
Java:driver.rotate(ScreenOrientation.LANDSCAPE);
Python:driver.orientation = "LANDSCAPE"
Get the current geo location
Java:Location location = driver.location(); // Must be a driver that implements LocationContext
Python:location = self.driver.location()
Set the current geo location
Java:driver.setLocation(new Location(49, 123, 10)); // Must be a driver that implements LocationContext
Python:self.driver.set_location(49, 123, 10)
Get the log for a given log type. Log buffer is reset after each request
Java:Set<String> logTypes = driver.manage().logs().getAvailableLogTypes();
Python:log_types = driver.log_types();
Get the log for a given log type. Log buffer is reset after each request
Java:LogEntries logEntries = driver.manage().logs().get("driver");
Python:logs = driver.get_log(‘driver‘);
Update the current setting on the device
Java:driver.setSetting(Setting.WAIT_FOR_IDLE_TIMEOUT, Duration.ofSeconds(5));
Python:self.driver.update_settings({"sample": "value"}))
Retrieve the current settings on the device
Java:Map<String, Object> settings = driver.getSettings();
Python:self.driver.get_settings
原文:https://www.cnblogs.com/music378/p/10487327.html