forceedge01 / behat-fail-aid

Get more out of your test suite by getting it to work with you when tests fail. Works with Goutte and MinkExtension (Selenium2Driver)
MIT License
28 stars 6 forks source link

Creating screenshot from chrome driver #13

Closed YurkinPark closed 5 years ago

YurkinPark commented 5 years ago

No possibility to make screenshot during testing with chrome driver. Do we really need $driver instanceof Selenium2Driver condition here https://github.com/forceedge01/behat-fail-aid/blob/001d42bcc5d84dea1d7d03655fdb24fc5f6d86e4/bootstrap/Context/FailureContext.php#L416 ?

forceedge01 commented 5 years ago

Thanks for logging this issue @YurkinPark, it is necessary to have but it can be extended to work with ChromeDriver. Will raise a PR soon for this.

forceedge01 commented 5 years ago

As far as I remember, this extension does infact support ChromeDriver as it is. Can you please share your ChromeDriver configuration in the behat.yml file please? The way i've used it in the past is as follows in behat.yml

javascript:
                    selenium2:
                        browser: chrome
                        wd_host: http://127.0.0.1:9515
                        capabilities: { "browser": "chrome", "version": "*", 'chrome': {'switches':['--start-maximized', "--headless", "--blink-settings=imagesEnabled=false", "--disable-extensions"]}}

ChromeDriver runs on the following address by default: http://127.0.0.1:9515

YurkinPark commented 5 years ago

Thanks for quick response! Here is behat conf

default:
  extensions:
    Behat\MinkExtension:
      browser_name: chrome
      base_url: http://<path_to_site>
      sessions:
        default:
          chrome:
            api_url: http://0.0.0.0:9222
            validate_certificate: false

We are running chrome in docker with this command docker run -d --init --rm --name project_chrome zenika/alpine-chrome --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --no-sandbox --entrypoint "" chromium-browser --headless --disable-gpu --disable-web-security

forceedge01 commented 5 years ago

Thanks @YurkinPark that helps, could you also share the dev composer packages you are using with behat?

YurkinPark commented 5 years ago

"dmore/behat-chrome-extension": "^1.3", "genesis/behat-fail-aid": "^2.0",

behat installs as requirements of dmore/behat-chrome-extension

piggito commented 5 years ago

I submitted a PR extending support to other drivers which implement https://github.com/minkphp/Mink/blob/master/src/Driver/DriverInterface.php Please have a look at it.

forceedge01 commented 5 years ago

Thanks @piggito , i've commented on your PR. @YurkinPark , i understand that you're not getting the screenshot in png format, but you should still get a html version of the page - is that not working for you?

If the html you're getting isn't correct because of broken links pointing to css and javascript, please have a look at siteFilters section of the README to fix those. Html pages are far more helpful in analysing the situation. Here is a link to the section: https://github.com/forceedge01/behat-fail-aid#sitefilters-option

davidferlay commented 5 years ago

Hi @forceedge01 !

We do get HTML screenshots but in some case PNG screenshots are useful too I'm begining to think it could be useful to be able to generate both HTML + PNG versions of screenshot > i'll open another issue to discuss it)

Main point here is to get PNG to be generated using chrome driver too)

YurkinPark commented 5 years ago

hi @forceedge01 , yes. html mode works perfect

forceedge01 commented 5 years ago

@YurkinPark Finally got around to resolving this - the PR https://github.com/forceedge01/behat-fail-aid/pull/20

davidferlay commented 5 years ago

Thanks @forceedge01 ! I'll test 2.3.2 release next week hopefully and let you know if any issue

Btw shouldn't github project name be updated too ?

Get more out of your test suite by getting it to work with you when tests fail. Works with Goutte and MinkExtension (Selenium2Driver)

davidferlay commented 5 years ago

FYI all good with latest version including these changes)

2019-09-23_16-12

I believe you can close this issue @forceedge01

jraviotta commented 3 years ago

Sorry to comment on this old closed post. @davidferlay I see you were able to configure chrome driver to save screenshots. Can you please share your configuration and custom functions in FeatureContext.php? I have had a hard time getting this to work with docker containers.

forceedge01 commented 3 years ago

@jraviotta thanks for the comment. Do you not get a screenshot path printed or is the path broken? Sharing your output and config would greatly help.

jraviotta commented 3 years ago

Thanks for the response @forceedge01. I'm having trouble getting the project configured to take any screenshots. I'm using Lando on a Drupal 7 project.

Here's docker ps:

CONTAINER ID   IMAGE                                        COMMAND                  CREATED        STATUS        PORTS                                                                     NAMES
b711ad16928c   mailhog/mailhog:v1.0.0                       "/lando-entrypoint.s…"   20 hours ago   Up 20 hours   1025/tcp, 8025/tcp, 127.0.0.1:49366->80/tcp                               4pillars_mailhog_1
40f39d5016b4   quay.io/pantheon-public/build-tools-ci:6.x   "/lando-entrypoint.s…"   20 hours ago   Up 20 hours   127.0.0.1:49365->9223/tcp                                                 4pillars_qa_1
f28a5e2540c6   robcherry/docker-chromedriver:latest         "/lando-entrypoint.s…"   20 hours ago   Up 20 hours   4444/tcp                                                                  4pillars_chromedriver_1
e3cc8c222c1a   bitnami/nginx:1.17.10-debian-10-r52          "/lando-entrypoint.s…"   20 hours ago   Up 20 hours   8080/tcp, 8443/tcp, 127.0.0.1:49368->80/tcp, 127.0.0.1:49367->443/tcp     4pillars_appserver_nginx_1
5a6b5e8d3684   bitnami/mysql:5.7.29-debian-10-r51           "/lando-entrypoint.s…"   20 hours ago   Up 20 hours   127.0.0.1:1337->3306/tcp                                                  4pillars_database_1
3237e30e030a   phpmyadmin/phpmyadmin:5.0.2                  "/lando-entrypoint.s…"   20 hours ago   Up 20 hours   127.0.0.1:49361->80/tcp                                                   4pillars_pma_1
ac6812921672   devwithlando/php:7.1-fpm-2                   "/lando-entrypoint.s…"   20 hours ago   Up 20 hours   9000/tcp                                                                  4pillars_appserver_1
51c73c2fc7e1   node:10                                      "/lando-entrypoint.s…"   20 hours ago   Up 20 hours                                                                             4pillars_node_1
af4c8f023ccb   traefik:2.2.0                                "/lando-entrypoint.s…"   23 hours ago   Up 23 hours   127.0.0.1:80->80/tcp, 127.0.0.1:443->443/tcp, 127.0.0.1:49153->8080/tcp   landoproxyhyperion5000gandalfedition_

Here's part of behat.yml

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
        - FailAid\Context\FailureContext
  extensions:
    DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~
    Behat\MinkExtension:
      base_url: http://4pillars.lndo.site
      goutte: ~
      browser_name: chrome
      show_cmd: chrome %s
      sessions:
        default:
          chrome:
            api_url: "http://qa:9223"
            validate_certificate: false
        javascript:
          chrome:
            api_url: "http://4pillars.lndo.site"
            download_behavior: allow
            download_path: /tests/download

Here is a test

Feature: Contact form
    In order to send a message to the site administrators
    As a visitor
    I should be able to use the site-wide contact form

  @javascript @testing
  Scenario: A visitor can use the site-wide contact form     # features/contact-form.feature:7
    Given I am at "contact/feedback"                         # Drupal\DrupalExtension\Context\MinkContext::assertAtPath()
      Could not fetch version information from http://172.21.0.7:9223/json/version. Please check if Chrome is running. Please see docs/troubleshooting.md if Chrome crashed unexpected. (RuntimeException)
    When I fill in "name" with "John Doe"                    # Drupal\DrupalExtension\Context\MinkContext::fillField()
    And I fill in "mail" with "john@doe.com"                 # Drupal\DrupalExtension\Context\MinkContext::fillField()
    And I fill in "subject" with "Hello world"               # Drupal\DrupalExtension\Context\MinkContext::fillField()
    And I fill in "message" with "Lorem Ipsum"               # Drupal\DrupalExtension\Context\MinkContext::fillField()
    And I press "Send message"                               # Drupal\DrupalExtension\Context\MinkContext::pressButton()
    Then I should see the text "Your message has been sent." # Drupal\DrupalExtension\Context\MinkContext::assertTextVisible()
    And I take a screenshot

--- Failed scenarios:

    features/contact-form.feature:7

1 scenario (1 failed)
8 steps (1 failed, 1 undefined, 6 skipped)
0m0.26s (42.02Mb)

First problem, I need a snippet in FeatureContext to handle "And I take a screenshot" >> <snippet_undefined><snippet_keyword>default</snippet_keyword> suite has undefined steps

Second problem, I don't think the right container is running Could not fetch version information from http://172.21.0.7:9223/json/version. Please check if Chrome is running.

In case you are familiar with lando.yml here's my services section

services:
  appserver:
    config:
      php: .vscode/php.ini
    build:
      - composer install
      - mkdir -p ~/.drush/site-aliases
      - ln -sf /app/drush/4pillars.aliases.drushrc.php ~/.drush/site-aliases/4pilars.drushrc.php
    overrides:
      environment:
        MINK_DRIVER_ARGS: '["chrome", null, "http://chromedriver:4444/wd/hub"]'
        MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", null, "http://chromedriver:4444/wd/hub"]'
        MINK_DRIVER_CLASS: 'Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver'
        SIMPLETEST_DB: 'mysql://drupal:drupal@database/drupal'
        SIMPLETEST_BASE_URL: 'https://4pillars.lndo.site/'
        PHP_IDE_CONFIG: "serverName=appserver"
        BEHAT_PARAMS: '{"extensions" : {"Behat\\MinkExtension" : {"base_url" : "http://appserver/"}, "Drupal\\DrupalExtension" : {"drush" :   {  "root":  "." }}}}'

  chromedriver:
    type: compose
    services:
      image: robcherry/docker-chromedriver:latest
      expose:
        - "4444"
      environment:
        CHROMEDRIVER_WHITELISTED_IPS: ""
        CHROMEDRIVER_URL_BASE: "/wd/hub"
      security_opt:
        - seccomp:unconfined
      command: ["/usr/local/bin/supervisord", "-c", "/etc/supervisord.conf"]
      ports:
        4444:4444

  qa:
    type: compose
    services:
      image: quay.io/pantheon-public/build-tools-ci:6.x
      user: root
      ports:
        - '9223'
      command: >-
        "google-chrome --disable-gpu --headless 
        --remote-debugging-address=0.0.0.0 --remote-debugging-port=9223
        --no-sandbox </dev/null &>/dev/null &"

Thanks for any help you can provide. I have seen many tutorials with selenium but none for a full configuration of chrome driver for Drupal.

forceedge01 commented 3 years ago

@jraviotta you may want to open a new issue for this to discuss further, but what i've noticed so far from your setup is that your behat.yml extensions section doesn't have the failAid block in it to activate the extension. It does have the context which is fine. The default config suggested on the readme is:

#behat.yml
default:
  suites:
    default:
      contexts:
        - FailAid\Context\FailureContext
  extensions:
    FailAid\Extension: ~

Can you add the extension bit and try again? There may be other issues but one thing is clear, the extension isn't kicking in at all.