docker - CasperJS doesn't load content injected by Angular router -
i'm preparing example project on github accompany course i'm working on how write functional tests dockerized applications. application has part angular2 single-page app, i'm trying test app casperjs (i've tried behat same problem explained below).
when running tests in casperjs it's if routing in angular doesn't load tests, mean can assert things in index template exist (like page title example) things inside <app-root></app-root>
tags don't load tests.
the code
here index template:
<!doctype html> <html lang="en"> <head <meta charset="utf-8"> <title>testproject</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <app-root></app-root> </body> </html>
the test is:
casper.test.begin('tests homepage structure', function suite(test) { casper.start('http://web', function() { // works because title set in "parent" template. test.asserttitle("testproject", "title correct"); casper.wait(2000); // fails, i'm guessing because h2 in "child" template, // seems casperjs doesn't render angular2 app correctly // , child route templates not injected page correctly. test.assertvisible('h2'); }); casper.run(function() { test.done(); }); });
here's output of test:
test file: homepage.js # tests homepage structure [info] [phantom] starting... [info] [phantom] running suite: 2 steps pass tests homepage structure (nan test) [debug] [phantom] opening url: http://web/, http [debug] [phantom] navigation requested: url=http://web/, type=other, willnavigate=true, ismainframe=true [debug] [phantom] url changed "http://web/" [debug] [phantom] injected casper client-side utilities [info] [phantom] step anonymous 2/2 http://web/ (http 200) pass title correct fail selector visible # type: assertvisible # file: homepage.js # subject: false # selector: "h2" [info] [phantom] step anonymous 2/2: done in 178ms. [info] [phantom] step _step 3/3 http://web/ (http 200) [info] [phantom] step _step 3/3: done in 196ms. [info] [phantom] wait() finished waiting 2000ms. [info] [phantom] done 3 steps in 2215ms
note these tests , web running inside docker containers, that's why hostname in code above "web" , not ip.
the application on github here. run application docker-compose up
in root , browse http://127.0.0.1:81/. run casperjs tests run ./tests/web/run_functional_test.sh
, don't need run docker-compose up
beforehand.
stuff tried
i have tried see if casperjs running problem outputting console errors on casperjs's loading of page haven't found suspicious.
the application works when run in browser, can see content router injected index template.
i have tried using resurrectio visit page in chrome, click few things , export test directly casperjs test file, automatically generated test fails same reason, content injected router not accessible casperjs.
i have tried using behat , selenium similar results. suggests problem not casperjs/phantomjs (maybe angular setup?).
the question
i'm no phantomjs/selenium expert understood can render javascript , it's normal expect casperjs , behat should able run assertions on things angular router inserts page, wrong in assuming this?
if not, going on tests? why can't casperjs tests run assertions against templates in routes?
in end problem simple one, simple ones ones make pull hair out.
from within web application using "127.0.0.1:82" connection string of api. worked in local because docker-compose file mapped port 82 of host wasn't mapping port 82 tests, web couldn't connect api. fix here.
i'm no phantomjs/selenium expert understood can render javascript , it's normal expect casperjs , behat should able run assertions on things angular router inserts page, wrong in assuming this?
i of course correct in assuming this.
Comments
Post a Comment