【问题标题】:Running Protractor through a batch file通过批处理文件运行量角器
【发布时间】:2017-01-16 15:10:33
【问题描述】:

正如标题所暗示的,我正在寻找一种通过批处理运行 Protractor 测试的方法,然后我将设置一个任务调度程序。我在这里发现了另一个与我的需求相似的问题,但它很快就死路了。

这是理想的情况:

  1. Scheduled Task 启动一个运行 webdriver 服务器的批处理文件

    • 问题:命令提示符打开并执行启动命令后,如何打开第二个窗口以启动量角器命令?
  2. 该批处理文件 A) 调用以执行量角器配置的另一个批处理文件,如上述问题所述。或者 B) 打开另一个执行量角器命令的命令提示符。

  3. 一旦测试完成,两个命令提示符都会关闭。

我有超级非常基本的 3 行批处理来打开网络服务器,但我坚持下一步要做什么才能真正开始测试而不中断网络服务器。

编辑:代码尝试

文件 1 包含

cd "C:\Protractor\"
call "C:\bat2.bat"
webdriver-manager start

文件2包含

START cmd /k
cd "C:\Protractor\"
protractor test.config.js

这条路线按预期打开了 2 个命令提示符,但是当调用 bat2 时,它只会在第一个命令提示符下执行 bat2 函数,而在第二个窗口中没有任何反应。一旦命令提示符 1 中的 jasmine 规范超时,webdriver 就会启动。这是根据线条的流动来理解的。

我也尝试将这些命令合并到一个文件中,但得到了相同的结果。我试过只使用一个命令提示符,但是一旦 webdriver 启动服务器,就无法输入新命令。

我猜更简单,如何在命令提示符之间更改焦点并向每个提示符发送相应的命令?

有一个步骤 4 超出了范围,但如果它很容易回答,那么无论如何都会令人惊叹:在测试执行后,会在本地生成一个 HTML 报告文件。我想自动化将这些文件通过电子邮件发送到特定邮件组的过程。这也可以通过批处理命令来实现吗?

提前感谢您的帮助。

【问题讨论】:

  • 您先向我们展示您拥有的代码并尝试完成这项工作。
  • 已添加。抱歉,没有多少文字就足够了。以前没有处理过批次,所以我确定我的措辞和例子都离题了。

标签: batch-file selenium-webdriver cmd jasmine protractor


【解决方案1】:

新版本的 Protractor 可以自行启动服务器。您无需创建单独的 bat 文件来启动服务器。

请参阅下面来自official Protractor documentation 的摘录,其中显示了运行案例的各种选项。

1 和 5 都适合你

exports.config = {
  // ---------------------------------------------------------------------------
  // ----- How to connect to Browser Drivers -----------------------------------
  // ---------------------------------------------------------------------------
  //
  // Protractor needs to know how to connect to Drivers for the browsers
  // it is testing on. This is usually done through a Selenium Server.
  // There are five options - specify one of the following:
  //
  // 1. seleniumServerJar - to start a standalone Selenium Server locally.
  // 2. seleniumAddress - to connect to a Selenium Server which is already
  //    running.
  // 3. sauceUser/sauceKey - to use remote Selenium Servers via Sauce Labs.
  // 4. browserstackUser/browserstackKey - to use remote Selenium Servers via BrowserStack.
  // 5. directConnect - to connect directly to the browser Drivers.
  //    This option is only available for Firefox and Chrome.

只需使用 jar 位置和端口详细信息配置 Protractor conf.js,它将创建一个本地服务器并执行案例

// ---- 1. To start a standalone Selenium Server locally ---------------------
  // The location of the standalone Selenium Server jar file, relative
  // to the location of this config. If no other method of starting Selenium
  // Server is found, this will default to
  // node_modules/protractor/selenium/selenium-server...
  seleniumServerJar: null,
  // Can be an object which will be passed to the SeleniumServer class as args.
  // See a full list of options at
  // https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/remote/index.js
  // If you specify `args` or `port` in this object, it will overwrite the values
  // set via the deprecated config values `seleniumPort` and `seleniumArgs`.
  localSeleniumStandaloneOpts: {
    // The port to start the Selenium Server on, or null if the server should
    // find its own unused port.
    port: null,
    // Additional command line options to pass to selenium. For example,
    // if you need to change the browser timeout, use
    // seleniumArgs: ['-browserTimeout=60']
    args: []
  },

只要做到这一点,你就会一切都好

START cmd /k
cd "C:\Protractor\"
protractor test.config.js

【讨论】:

  • 你知道使用 geckodriver 是如何工作的吗?我终于让 gecko 在 Chrome、IE 和 Firefox 上正常工作了——但是当使用 geckodriver 时,这个“内联”服务器路由似乎并不想很好地发挥作用。如果有帮助的话,我可以分享我的配置文件和到目前为止我尝试过的内容。让我知道。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多