Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log in when current language different from English #524

Closed
leymannx opened this issue Jan 22, 2019 · 6 comments
Closed

Log in when current language different from English #524

leymannx opened this issue Jan 22, 2019 · 6 comments

Comments

@leymannx
Copy link

leymannx commented Jan 22, 2019

v3.4.1. – I have a French site here. Actually it's just language negotiation set to use Domain instead of path prefixes. And I have an edit.feature with a scenario that just ensures certain roles can log in and edit random nodes:

Feature: Let's login as users with certain roles and check that node edit
  forms are accessible.

  @api
  Scenario: Login as publisher and try to edit some random node forms
    Given I am logged in as a publisher
    # ...

Logging in using the English base URL english-site.localhost works just fine. But running the same test against the French base URL frensh-site.localhost gives me following error:

Given I am logged in as a publisher                               # Drupal\DrupalExtension\Context\DrupalContext::assertAuthenticatedByRole()
  Form field with id|name|label|value|placeholder "Password" not found. (Behat\Mink\Exception\ElementNotFoundException)

I then might have found the culprit here:

$element->fillField($this->getDrupalText('username_field'), $user->name);
$element->fillField($this->getDrupalText('password_field'), $user->pass);
$submit = $element->findButton($this->getDrupalText('log_in'));

When I change the above to use the name attributes of the input elements and the translated "Log in" string it starts working again.

$element->fillField('name', $user->name);
$element->fillField('pass', $user->pass);
$submit = $element->find('xpath', '//form[@id="user-login-form"]')->find('xpath', '//input[@type="submit"]');

Do we need to fix this? Or is there already some getTranslationFromContext kind of functionality implemented at some place and I only need to define a default_language or something like that in my behat.yml?

Refs #93

@leymannx
Copy link
Author

leymannx commented Jan 22, 2019

The corresponding behat.yml for the French site:

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
        - Drupal\DrupalExtension\Context\BigPipeContext
        - IntegratedExperts\BehatScreenshotExtension\Context\ScreenshotContext
        - MOrtola\BehatSEOContexts\MetaContext
        - MOrtola\BehatSEOContexts\LocalizationContext
        - MOrtola\BehatSEOContexts\RobotsContext
        - MOrtola\BehatSEOContexts\RedirectContext
        - MOrtola\BehatSEOContexts\SitemapContext
        - MOrtola\BehatSEOContexts\HTMLContext
        - MOrtola\BehatSEOContexts\PerformanceContext
        - MOrtola\BehatSEOContexts\SocialContext
  extensions:
    Behat\MinkExtension:
      base_url: http://french-site.localhost
      goutte: ~
      selenium2:
        wd_host: http:/french-site.localhost:4444/wd/hub
        capabilities:
          marionette: true
          browser: chrome
      browser_name: chrome
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: drupal
      drupal:
        drupal_root: %paths.base%/../../web
    Bex\Behat\ScreenshotExtension:
      screenshot_taking_mode: failed_steps
      image_drivers:
        local:
          screenshot_directory: ../tests/behat/screenshots/failed_steps/chrome
    IntegratedExperts\BehatScreenshotExtension:
      dir: %paths.base%/screenshots/chrome
      fail: true
      purge: false

leymannx added a commit to leymannx/drupalextension that referenced this issue Jan 23, 2019
@jonathanjfshaw
Copy link
Contributor

Unfortunately it's not always easy to find things in the docs:
https://behat-drupal-extension.readthedocs.io/en/3.1/blackbox.html

Drupal\DrupalExtension:
  text:
    log_out: "Sign out"
    log_in: "Sign in"
    password_field: "Enter your password"
    username_field: "Nickname"

@leymannx
Copy link
Author

Gosh, I googled this sooo hard... Thank you! Thanks a lot!

On the other hand, now after I provided this patch, it honestly seems a bit more sustainable to make the login language-neutral in the first place...

@leymannx
Copy link
Author

Now I understand what getDrupalText() is supposed to do! 💡 I was so blind...

@jonathanjfshaw
Copy link
Contributor

Log in / out has been quite a painful issue here. I know some new work has been done that is in the 4.0 releases (see e.g. #62 #425 #398), I'm not sure how far it goes though. Contributions to making it more robust definitely appreciated!

@pfrenssen
Copy link
Collaborator

It looks like this is resolved, so this can be closed. Thanks @jonathanjfshaw for providing the answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants