jeromeerasmus/selenium-automate

该软件包最新版本(0.1.2)没有可用的许可信息。

BrowserStack Local 的 PHP 绑定

0.1.2 2018-08-27 11:01 UTC

This package is auto-updated.

Last update: 2024-09-23 18:11:08 UTC


README

这个库旨在帮助 Selenium 和 Browserstack 连续集成,用于 BeHat 测试的本地 PHP。有三种方式设置和运行测试

  • 在本地运行 Selenium 测试
  • 在 Docker 中运行 Selenium 测试(使用 bitbucket Pipelines)
  • 运行 Browserstack

可以使用以下 composer 命令将库安装到您的 PHP 项目中,该命令将从 Packagist 安装库。

require jeromeerasmus/selenium-automate:dev-master

在本地运行 Selenium 测试

要求

需要 Firefox v39.0 和 Selenium v1.4.0,您可以从以下链接下载正确的 Firefox 版本: https://ftp.mozilla.org/pub/firefox/releases/39.0/ 请记住,一旦安装,立即关闭 Firefox 的自动更新。

设置

首先获取最新的 JRE 并将其安装到您的机器上,因为 Selenium 在 JRE 上运行。您首先需要安装 selenium 到您的机器上,以便运行 Selenium 测试。在 OSX 上,这应该像下面这样简单

brew install selenium-server-standalone

接下来,使用以下命令配置您的 composer.json 文件,以便能够在本地运行 Selenium 测试。

"scripts": {
    "start-selenium": "vendor/bin/manager start",
    "run-selenium": "vendor/bin/behat --config=conf.selenium.yml -f pretty -o std -f junit -o results"
  }

接下来,将 dist.conf.selenium.yml 和 dist.conf.browserstack.yml 复制到 conf.selenium.yml 和 conf.browserstack.yml,然后编辑它们以匹配您的项目规范。您只需要编辑此配置中的 base_url 字段。

执行测试

然后执行以下操作:首先在一个新的终端窗口中启动 Selenium。让它运行。

composer start-selenium

然后打开一个新的终端窗口,并使用以下命令运行示例测试

composer run-selenium

在 Docker 中运行 Selenium 测试(使用 bitbucket Pipelines)

此配置允许您使用 Docker 运行测试。

要求

您的机器上已安装 Docker 和 Docker Compose。(当然)

设置

在根目录中执行以下步骤

  1. 创建一个包含以下内容的 Dockerfile

    FROM mycrm/base
    
    COPY . /var/specs
    WORKDIR /var/specs
    
    # Config
    ENTRYPOINT ["vendor/bin/behat"]
    
  2. 创建一个包含以下内容的 docker-compose 文件

    version: '2'
    services:
      specs:
        build: .
        volumes:
          - .:/var/specs
        container_name: mycrm-specs
        links:
         - firefox-server
        environment:
          BEHAT_PARAMS: '{"extensions" : {"Behat\\MinkExtension" : {"base_url" : "https://it.wikipedia.org/"}}}'
    
      firefox-server:
        container_name: mycrm-specs-server
        #image: selenium/standalone-firefox-debug:2.53.0
        image: selenium/standalone-firefox:2.53.0
        ports:
          - "4444:4444"
          - "5900:5900"
    

现在,您可以执行以下命令,该命令将构建 Docker 镜像并运行测试。

docker-compose -f docker-compose.yml run --rm specs  --config=conf.selenium-docker.yml

设置 Bitbucket Pipelines 脚本

您可以通过在根目录中创建以下 bitbucket-pipelines.yml 文件来在 Bitbucket Pipelines 上运行测试。您可以使用以下脚本作为内容。

pipelines:
  default:
    - step:
        image: jeromeerasmus/docker-alpine-php-composer:7.0
        services:
          - docker
        script: 
          - composer install
          - docker-compose -f docker-compose.yml run --rm specs  --config=conf.selenium-docker.yml

Selenium Automate(与 Browserstack 一起使用)

Behat 与 BrowserStack 的集成。

设置

  • 将存储库克隆到您的项目根目录
  • 在您的本地机器上切换到存储库文件夹
  • 安装依赖项 composer install
  • 首先,将 dist.conf.selenium.yml 和 dist.conf.browserstack.yml 复制到 conf.selenium.yml 和 conf.browserstack.yml,然后编辑它们以匹配您的项目规范。
  • 然后,将 dist.env 文件复制到 .env 并使用您的 browserstack 密钥更新

创建 capabilities 配置文件

您定义一个 capabilities 配置文件来明确指定您将测试哪些浏览器/设备/操作系统。要获取来自 Browserstack 的完整更新列表的 capabilities,请运行以下命令

composer capabilities

这将列出所有 capabilities 的详尽列表。查看列表,并挑选出您要在其上运行测试的 capabilities。您可以使用这些 capabilities 更新您的 .yml 文件

一旦正确完成上述操作,您将能够运行测试。













## Running the Selenium tests 
First grab the latest JRE and install it on your machine as Selenium runs on the JRE. You first need to install selenium on your machine in order to run the Selenium tests. On OSX this should be as easy as: 

brew install selenium-server-standalone



Then perform the below:
First start Selenium 

composer start-selenium


Then run the test 

composer run-selenium


## Running the Browserstack tests 
To run a test in browserstack execute 

composer run-bs



### Manufaturing tests by the dozen
The below is some basic workflow tips to save you some time. The below is not essential to running your tests.

Scaffold a BeHat project structure and key files

./bin/behat --init


After writing your .feature file run the below to create the code snippet and auotmoatically place it into the 
Feature context file

./bin/behat --append-snippets


## Notes
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
* To test on a different set of browsers, check out  [platform configurator](https://www.browserstack.com/automate/php#setting-os-and-browser)