minkphp / MinkZombieDriver

Zombie.js driver for Mink framework
41 stars 49 forks source link

SinglePageApplication: Javascript is not executed #201

Closed yajo10 closed 2 years ago

yajo10 commented 2 years ago

Hey, I'm trying to get Min working. With Chromium everything works quite fine. All JavaScript is executed on a single page application. I've installed zombie global and followed strictly the examples. However, it does not executes JavaScript automatically. Did I miss a setting or anything else in the workflow?

   $driver = new \Behat\Mink\Driver\ZombieDriver(
        new \Behat\Mink\Driver\NodeJS\Server\ZombieServer()
    );
    $mink = new Mink(array(
        'zombie' => new \Behat\Mink\Session($driver),
        'browser' => new \Behat\Mink\Session(
            new ChromeDriver('http://localhost:9222', null, 'http://www.google.com')
        )
    ));
    $mink->setDefaultSessionName('zombie');

    $mink->getSession()->visit(env('WEB_URL')."/some-url/2a07e084-c49f-4900-9a6c-59570d987686");

    $page = $mink->getSession()->getPage();

    var_dump($page);
    print_r($page->getContent());

    $button = $page->findById('export');

    $button->click();

Executing with Zombie the page just the correct html and the script-includes, that should be executed. But that's not done. In Chrome the includes are working properly. Any hints or needed additional information?

    "behat/mink": "^1.9",
    "behat/mink-selenium2-driver": "^1.5",
    "behat/mink-zombie-driver": "^1.5",

     zombie@6.1.4

Thanks in advance!

aik099 commented 2 years ago

Does some simple JS page work for you, e.g. when you change page HTML via JS and then assert that in Mink?

yajo10 commented 2 years ago

Thanks for your fast reply! I've added an simple JS-Script-Tag, that replaces some text after the js-event load is fired. I can not assert that successfully in Mink. Do I have to tell Zombie somehow to execute the JS?

Edit: after fiddling around I got that replacing some text with js-script is working quite well. I did not assert correctly for that. I assumed that after calling $page->getContent() javascript was already executed. But this does not seem to be correct.

<!DOCTYPE html>
<html lang="de" translate="no">

<head>
  <meta charset="utf-8"/>
  <title>Some title</title>

  <base href="/"/>

  <meta name="color-scheme" content="light dark"/>
  <meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  <meta name="format-detection" content="telephone=no"/>
  <meta name="msapplication-tap-highlight" content="no"/>

  <link rel="icon" type="image/png" href="assets/icon/favicon.png"/>

  <!-- add to homescreen for ios -->
  <meta name="apple-mobile-web-app-capable" content="yes"/>
  <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<link rel="stylesheet" href="styles.css"></head>

<body>
  <app-root></app-root>
<script src="runtime.js" type="module"></script><script src="polyfills.js" type="module"></script><script src="vendor.js" type="module"></script><script src="main.js" type="module"></script></body>

So that's my original response, I get. But asserting an item, that should be added after executing all the included scripts does not succeed. Is there any option to find out, what's going on there?

aik099 commented 2 years ago

Do I have to tell Zombie somehow to execute the JS?

No.

We have a test suite in place on GitHub Actions, that tests that it works with both JS and HTML. It passes.

Maybe Zombie can't handle non-HTML5 tags, like <app-root></app-root>. Mink is just a wrapper around Zombie. You need to contact the Zombie developer at http://zombie.js.org/ to see if it can deal with such HTML.

yajo10 commented 2 years ago

Thanks a lot for your reply. I'm sorry for bothering you!

Just as a reference: I've asked the question again there: https://github.com/assaf/zombie/issues/1218