Appium-API-Session

Session

Create New Session

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)

End Session

Java:driver.quit();
Python:self.driver.quit()

Get Session Capabilities

Retrieve the capabilities of the specified session

Java:Map<String, Object> caps = driver.getSessionDetails();
Python:desired_caps = self.driver.desired_capabilities()

Go Back

Navigate backwards in the browser history, if possible (Web context only)

Java:driver.back();
Python:self.driver.back()

Take Screenshot

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 Page Source

Get the current application hierarchy XML (app) or page source (web)

Java:String pageSource = driver.getPageSource();
Python:source = self.driver.page_source

Set Timeouts

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 Implicit Wait Timeout

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 Script Timeout

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 Orientation

Get the current device/browser orientation

Java:ScreenOrientation orientation = driver.getOrientation();
Python:orientation = self.driver.orientation()

Set Orientation

Set the current device/browser orientation

Java:driver.rotate(ScreenOrientation.LANDSCAPE);

Python:
driver.orientation = "LANDSCAPE"

Get Geolocation

Get the current geo location

Java:Location location = driver.location(); // Must be a driver that implements LocationContext
Python:location = self.driver.location()

Set Geolocation

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 available log types

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 Logs

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 Device Settings

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 Device Settings

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值