Create a 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 = {'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) |
Javascript | // webdriver.io example let options = { desiredCapabilities: { platformName: 'Android' ,platformVersion: '7.0' ,automationName: 'UiAutomator2' ,app: path.resolve( 'path' ,'to' , 'app.apk' )}};let client = driver.newSession(options); // wd example let driver = await wd.promiseChainRemote({ host: '127.0.0.1' ,port: 4723 }); let desiredCaps = { platformName: 'Android' ,platformVersion: '7.0' ,deviceName: 'Android Emulator' ,app: path.resolve( 'path' , 'to' ,'app.apk' )};await driver.init(desiredCaps); |
Ruby | # ruby_lib example APP_PATH = '../../path/to/app.app' desired_caps = { caps: { platformName: 'iOS' ,platformVersion: '10.2' ,deviceName: 'iPhone 6' ,app: APP_PATH, automationName: "XCUITest" } } Appium::Driver.new(desired_caps).start_driver # ruby_lib_core example ::Appium::Core.for(desired_caps).start_driver |
C# | AppiumOptions capabilities = new AppiumOptions(); appiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android" );appiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "7.1.1" );appiumOptions.AddAdditionalCapability(MobileCapabilityType.DeviceName, "Android Device" );appiumOptions.AddAdditionalCapability( "appPackage", "com.instagram.android" );appiumOptions.AddAdditionalCapability( "appActivity","com.instagram.android.activity.MainTabActivity" );AndroidDriver driver = new AndroidDriver(new Uri( "http://127.0.0.1:4723/wd/hub" ), appiumOptions); |
PHP |
服务器应尝试创建与所需功能最匹配的会话。
与上篇一致
与上篇一致
POST /session
None
name | type | description |
---|---|---|
desiredCapabilities | object | (JSONWP specification) Object describing session’s desired capabilities |
requiredCapabilities | object | (JSONWP specification) Object describing session’s required capabilities that must be applied by remote end |
capabilities | object | (W3C specification) object containing ‘alwaysMatch’ and ‘firstMatch’ properties |
capabilities.alwaysMatch | object | The desired capabilities that the remote end must match |
capabilities.firstMatch | array<object> | List of capabilities that the remote end tries to match. Matches the first in the list |
An object describing the session's capabilities (object) //描述会话功能的对象(object)