sensiolabs / BehatPageObjectExtension

MIT License
116 stars 48 forks source link

Expected to be on "xxx" but found "" instead #111

Closed bartonhammond closed 6 years ago

bartonhammond commented 6 years ago

I'm using MinkExtension and running locally is fine. But when I try to run w/ CrossBrowserTesting I fail. I'm working on extending MinkExtension w/ a CBT Factory patterned after BrowserStack Factory.

Anyway, here is my behat-cbt.yml

default:
  suites:
    default:
      paths: ["%paths.base%/features/temp/home.feature"]
      local_screenshots: false      
      contexts: [ThinkWellContext]

  extensions:
    Behat\MinkExtension:
      default_session: my_session
      base_url: https://twlw.wpengine.com
      browser_name: 'chrome'      
      sessions:
        my_session:
          cross_browser_testing:
            server: "crossbrowsertesting.com"
            user: "b@wist.com"
            key: "ud"
            capabilities: 
              name: "Name"
              build: "1.0.0"
              record_video: true
              record_network: true
              max_duration: "14400"
              browserName: 'Chrome'
              version: '62x64'
              platform: 'Mac OSX 10.12'
              screenResolution: '1366x768'

    SensioLabs\Behat\PageObjectExtension:
      namespaces:
        page: [Page]
        element: [Page]

Heres the output:

~/projects/thinkwell-livewell/wp-content/themes/jumpoff (master)$ vendor/bin/behat --config behat-cbt.yml 
Feature: Home
  In order to navigate the site
  As a visitor
  I want to test navigation

  Background:                           # features/temp/home.feature:6
    Given I reset "all" data            # ThinkwellContext::iResetData()
      │ Reset Post Data
      │ Reset User Program Data
      │ Reset User Data
      │ 
    Given I am a visitor                # ThinkwellContext::iAmAVisitor()
    When I go to the "Home" page        # ThinkwellContext::iGoToThePage()
      Expected to be on "https://twlw.wpengine.com/" but found "" instead (SensioLabs\Behat\PageObjectExtension\PageObject\Exception\UnexpectedPageException)
    And I take a screenshot "home page" # ThinkwellContext::iTakeAScreenshot()

  @javascript
  Scenario: I can see multiple links            # features/temp/home.feature:13
    Then I should see "Programmes" link         # ThinkwellContext::iShouldSeeLink()
    And I should see "How It Works" link        # ThinkwellContext::iShouldSeeLink()
    And I should see "Self-Help/Resources" link # ThinkwellContext::iShouldSeeLink()
    And I should see "Try It Free" link         # ThinkwellContext::iShouldSeeLink()
    And I take a screenshot "Home page"         # ThinkwellContext::iTakeAScreenshot()

--- Failed scenarios:

    features/temp/home.feature:13

1 scenario (1 failed)
9 steps (2 passed, 1 failed, 6 skipped)

I'm not seeing any activity w/in CBT. I'm kind of lost to how to debug this. My experience has been when I see a similar message to this that the browser was never started. I don't see any browser starting.

jakzal commented 6 years ago

What's in your When I go to the "Home" page step?

jakzal commented 6 years ago

If you're able to upload (perhaps a simplified) reproducer project somewhere, I'd be happy to take a look.

bartonhammond commented 6 years ago

Hi @jakzal

I created a fork of MinkExtension: https://github.com/bartonhammond/MinkExtension

I created sample project: https://github.com/bartonhammond/MinkExtensionProject

You'll need a CrossBrowserTesting (CBT) account: https://crossbrowsertesting.com/freetrial

I put instructions in Readme

Once the CBT account is setup and behat-cbt.yml is updated, you can reproduce error w/ composer behat-cbt

Thanks for your help!

jakzal commented 6 years ago

I did some quick debugging and it turns out that this error is rather misleading as webdriver failed to initialise the session properly. I created #112 to capture it and see if this could be improved.

Your problem is in no way related to the page object extension. AbstractWebDriver::curl() gets an empty response from CBT. Probably because of misconfiguration. It's not handled properly, and this could be improved in webdriver.

Furthermore, CBT's example project just works for me, so the problem might be in a way webdriver is initialised by your extension.

If you're working on integrating with CBT, I suggest you try to do it with the mink extension alone first. Once you made it work, move to integrating with page objects. I'd also consider creating your own extension once you make it working (as opposed to forking mink).

jakzal commented 6 years ago

One difference I noticed is that CBT's example project uses RemoteWebDriver, while Mink's Selenium2Driver works with WebDriver.

bartonhammond commented 6 years ago

@jakzal Thanks for looking into this.

I did work with the CBT example project - it works for me too and I noticed the Remote usage.

I forked MinkExtension as it supports multiple Drivers - I just create a CBT driver - see https://github.com/bartonhammond/MinkExtension/tree/master/src/Behat/MinkExtension/ServiceContainer/Driver I think it's the right way to add an additional service such as CBT.

I'll look to the MinkExtension project for help now. Thanks again!