设置所需的功能(desired_caps
)后,我的脚本出错了。错误是
if desired_capabilities is None:
^ IndentationError:意外缩进
以下是代码:
import unittest
from selenium import webdriver
from appium import webdriver
from appium import webdriver
from selenium.webdriver.common import desired_caps
from webdriver import WebDriver as Remote
class CNNEndToEnd(unittest.TestCase):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0.1'
desired_caps['deviceName'] = 'Samsung'
#desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk')
desired_caps['appPackage'] = 'com.android.vending'
desired_caps['appActivity'] = '.AssetBrowserActivity'
print desired_caps
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def testACNNInstallAndLaunch(self):
print "**************************"
print "********APP INSTALL*******"
print "**************************"
print "here---------"
#appid = "com.cnn.mobile.android.phone"
if (self.driver.is_app_installed("com.cnn.mobile.android.phone")):
print "-----App ALready Installed"
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(CNNEndToEnd)
unittest.TextTestRunner(verbosity=2).run(suite)
完整的错误消息:
Traceback (most recent call last):
File "/Users/manusimply/.p2/pool/plugins/org.python.pydev_5.8.0.201706061859/pysrc/_pydev_runfiles/pydev_runfiles.py", line 468, in __get_module_from_str
mod = __import__(modname)
File "/Users/manusimply/Desktop/Eclipse/CNN_PoC/CNN_New.py", line 2, in <module>
from appium import webdriver
File "/Users/manusimply/Desktop/Eclipse/Appium-Python-Client-0.2/appium/webdriver/__init__.py", line 19, in <module>
from webdriver import WebDriver as Remote
File "/Users/manusimply/Desktop/Eclipse/Appium-Python-Client-0.2/appium/webdriver/webdriver.py", line 15, in <module>
from selenium import webdriver
File "/Users/manusimply/Desktop/Eclipse/selenium-3.4.3/selenium/webdriver/__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "/Users/manusimply/Desktop/Eclipse/selenium-3.4.3/selenium/webdriver/firefox/webdriver.py", line 34, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "/Users/manusimply/Desktop/Eclipse/selenium-3.4.3/selenium/webdriver/remote/webdriver.py", line 79
if desired_capabilities is None:
^
IndentationError: unexpected indent
ERROR: Module: CNN_New could not be imported (file: /Users/manusimply/Desktop/Eclipse/CNN_PoC/CNN_New.py).
答案 0 :(得分:0)
您应该使用DesiredCapabilities对象,而不仅仅是要实现的功能列表。它会让你的生活更轻松。如下所示初始化变量,然后将您的功能添加到该变量中。
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
desired_caps = DesiredCapabilities.CHROME
有关在python中初始化webdriver的更多详细信息,请参阅此链接: http://selenium-python.readthedocs.io/getting-started.html
还要确保为每个功能使用正确的命名约定。这里列出了一些功能及其名称:https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
希望这有助于:)
答案 1 :(得分:0)
tenant_url= "https://{tenant}.sharepoint.com"
ctx_auth = AuthenticationContext(tenant_url)
site_url="https://{tenant}.sharepoint.com/sites/{yoursite}"
if ctx_auth.acquire_token_for_user("username","password"):
request = ClientRequest(ctx_auth)
options = RequestOptions("{0}/_api/web/".format(site_url))
options.set_header('Accept', 'application/json')
options.set_header('Content-Type', 'application/json')
data = request.execute_request_direct(options)
s = json.loads(data.content)
web_title = s['Title']
print("Web title: " + web_title)
else:
print(ctx_auth.get_last_error())
也要使用caps_caps。我建议包括udid并使用完整的appActivity路径。