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

SinglePageApplication: Javascript is not executed #201

Closed
yajo10 opened this issue Feb 17, 2022 · 4 comments
Closed

SinglePageApplication: Javascript is not executed #201

yajo10 opened this issue Feb 17, 2022 · 4 comments

Comments

@yajo10
Copy link

yajo10 commented Feb 17, 2022

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",

     [email protected]

Thanks in advance!

@aik099
Copy link
Member

aik099 commented Feb 17, 2022

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

@yajo10
Copy link
Author

yajo10 commented Feb 17, 2022

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
Copy link
Member

aik099 commented Feb 17, 2022

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
Copy link
Author

yajo10 commented Feb 17, 2022

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

Just as a reference: I've asked the question again there: assaf/zombie#1218

@yajo10 yajo10 closed this as completed Feb 17, 2022
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

2 participants