【问题标题】:How to start Appium server programatically in mac using ruby ?如何使用 ruby​​ 在 mac 中以编程方式启动 Appium 服务器?
【发布时间】:2018-11-04 09:58:42
【问题描述】:

有没有办法让 appium 在代码中启动?我正在尝试自动化 iOS 应用程序,因为 appium 只需要在我的测试运行时运行,所以让 appium 服务器始终运行对我来说没有意义。

现在我正在使用 Appium GUI 启动服务器。是否可以在将 WebDriver 连接到它之前在 Before 方法中添加一些东西来启动 appium 服务器,然后在 After 方法中终止它。

请帮助我在 Mac 中使用 Ruby 完成。

Appium 服务器版本:1.8.0 Mac 操作系统:10.13 节点:6.11 红宝石:2.5.1

提前致谢,

【问题讨论】:

    标签: appium


    【解决方案1】:

    从 Ruby 程序内部调用 shell 命令。

    `/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --selendroid-port 8082 --no-reset --local-timezone`
    

    相应更改路径或将 appium 应用复制到 Applications 文件夹

    【讨论】:

    • 感谢乔的回答。
    • AfterConfiguration 执行 'appium' end 。我在钩子文件中添加了这个。 Appium 正在启动,但此后功能文件未执行
    【解决方案2】:

    这里是用 Ruby 编写的 BDD 框架的解决方案。将这两个钩子粘贴到 hooks.rb 文件中

    启动服务器:

    AfterConfiguration do |config|
    pid = spawn ‘appium --address 0.0.0.0 --port 4723’
    Process.detach(pid)
    sleep(10)
    end
    

    AfterConfiguration 钩子将在 Cucumber 配置后运行。这个钩子只会运行一次,在加载支持之后但在加载特性之前。所以启动 Appium 服务器很有用。

    停止服务器:

    at_exit do
    exec ‘/usr/bin/killall -KILL node’
    end
    

    at_exit 将在所有功能文件执行后执行。所以在这个钩子中执行exec '/usr/bin/killall -KILL node'命令会在最后杀死服务器

    【讨论】:

    • 我收到以下错误:没有这样的文件或目录 - appium (Errno::ENOENT) 没有找到属于您的匹配进程
    猜你喜欢
    • 2018-10-07
    • 2019-01-14
    • 2021-04-13
    • 2019-07-15
    • 2016-04-17
    • 2017-10-22
    • 2018-10-14
    • 2017-07-19
    • 2019-06-19
    相关资源
    最近更新 更多