Skip to content

Commit a2bba19

Browse files
docs: Update README with the new options format (#722)
1 parent b267665 commit a2bba19

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

README.md

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -104,37 +104,38 @@ environment:
104104

105105
```python
106106
# Android environment
107-
import unittest
108107
from appium import webdriver
108+
# Options are only available since client version 2.3.0
109+
# If you use an older client then switch to desired_capabilities
110+
# instead: https://github.com/appium/python-client/pull/720
111+
from appium.options.android import UiAutomator2Options
109112
from appium.webdriver.common.appiumby import AppiumBy
110113
111-
desired_caps = dict(
112-
platformName='Android',
113-
platformVersion='10',
114-
automationName='uiautomator2',
115-
deviceName='Android Emulator',
116-
app=PATH('../../../apps/selendroid-test-app.apk')
117-
)
118-
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
114+
options = UiAutomator2Options().\
115+
set_capability('platformVersion', '10').\
116+
set_capability('deviceName', 'Android Emulator').\
117+
set_capability('app', PATH('../../../apps/selendroid-test-app.apk'))
118+
# Appium1 points to http://127.0.0.1:4723/wd/hub by default
119+
self.driver = webdriver.Remote('http://127.0.0.1:4723', options=options)
119120
el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='item')
120121
el.click()
121122
```
122123

123124
```python
124125
# iOS environment
125-
import unittest
126126
from appium import webdriver
127+
# Options are only available since client version 2.3.0
128+
# If you use an older client then switch to desired_capabilities
129+
# instead: https://github.com/appium/python-client/pull/720
130+
from appium.options.ios import XCUITestOptions
127131
from appium.webdriver.common.appiumby import AppiumBy
128132
129-
desired_caps = dict(
130-
platformName='iOS',
131-
platformVersion='13.4',
132-
automationName='xcuitest',
133-
deviceName='iPhone Simulator',
134-
app=PATH('../../apps/UICatalog.app.zip')
135-
)
136-
137-
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
133+
options = XCUITestOptions().\
134+
set_capability('platformVersion', '13.4').\
135+
set_capability('deviceName', 'iPhone Simulator').\
136+
set_capability('app', PATH('../../apps/UICatalog.app.zip'))
137+
# Appium1 points to http://127.0.0.1:4723/wd/hub by default
138+
self.driver = webdriver.Remote('http://127.0.0.1:4723', options=options)
138139
el = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='item')
139140
el.click()
140141
```
@@ -151,37 +152,44 @@ If your Selenium/Appium server decorates the new session capabilities response w
151152
Then python client will switch its endpoint to the one specified by the values of those keys.
152153

153154
```python
154-
import unittest
155155
from appium import webdriver
156-
157-
desired_caps = dict(
158-
platformName='iOS',
159-
platformVersion='13.4',
160-
automationName='xcuitest',
161-
deviceName='iPhone Simulator',
162-
app=PATH('../../apps/UICatalog.app.zip')
156+
# Options are only available since client version 2.3.0
157+
# If you use an older client then switch to desired_capabilities
158+
# instead: https://github.com/appium/python-client/pull/720
159+
from appium.options.ios import XCUITestOptions
160+
161+
options = XCUITestOptions().load_capabilities({
162+
'platformVersion': '13.4',
163+
'deviceName': 'iPhone Simulator',
164+
'app': PATH('../../apps/UICatalog.app.zip'),
165+
})
166+
167+
self.driver = webdriver.Remote(
168+
# Appium1 points to http://127.0.0.1:4723/wd/hub by default
169+
'http://127.0.0.1:4723',
170+
options=options,
171+
direct_connection=True
163172
)
164-
165-
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps, direct_connection=True)
166173
```
167174

168175
## Relax SSL validation
169176

170177
`strict_ssl` option allows you to send commands to an invalid certificate host like a self-signed one.
171178

172179
```python
173-
import unittest
174180
from appium import webdriver
175-
176-
desired_caps = dict(
177-
platformName='iOS',
178-
platformVersion='13.4',
179-
automationName='xcuitest',
180-
deviceName='iPhone Simulator',
181-
app=PATH('../../apps/UICatalog.app.zip')
182-
)
183-
184-
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps, strict_ssl=False)
181+
# Options are only available since client version 2.3.0
182+
# If you use an older client then switch to desired_capabilities
183+
# instead: https://github.com/appium/python-client/pull/720
184+
from appium.options.common import AppiumOptions
185+
186+
options = AppiumOptions()
187+
options.platform_name = 'mac'
188+
options.automation_name = 'safari'
189+
options.set_capability('browser_name', 'safari')
190+
191+
# Appium1 points to http://127.0.0.1:4723/wd/hub by default
192+
self.driver = webdriver.Remote('http://127.0.0.1:4723', options=options, strict_ssl=False)
185193
```
186194

187195
## Documentation

0 commit comments

Comments
 (0)