nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

InjectScript doesn't wait until the script is loaded #1548

Closed dennyjun closed 5 years ago

dennyjun commented 7 years ago

This error happens sometimes in Windows 10 PRO. I think that the script is being added to the DOM but it hasn't been loaded yet when I try to execute using code from the script after injectScript. I think the fix will need to change the injectScript method to use executeAsync instead of execute and use done in script.onload.

so...

return this.execute(function(u,i) {
    /* jshint browser:true */
    return (function(d){
        var e=d.createElement('script');
        var m=d.getElementsByTagName('head')[0];
        e.src=u;
        if(i){e.id=i;}
        m.appendChild(e);
        return e;
    })(document);
}, args, callback);

will need to be something like

return this.executeAsync(function(u,i) {
    /* jshint browser:true */
    return (function(d){
        ...
        e.src=u;
        e.onload = function() {done();};
        ...

will need timeoutsAsyncScript or some way to wait for the script to actually load

return this
    .timeoutsAsyncScript(timeout)    // add default
    .executeAsync(function(u,i) {
    ...

Example Test:

module.exports = {
    '@tags': ['search'],
    'Test' : browser => {
        browser
        .url('https://www.bing.com')
        .waitForElementVisible('body', 15000)
        .injectScript('https://cdnjs.cloudflare.com/ajax/libs/ramda/0.24.1/ramda.min.js')
        .execute(data => R.add(1, 2), [], (result) => assert.strictEqual(result.value, 3))
        .setValue('input[type=search]', 'nightwatch')
        .click('input[name=go]')
        .waitForElementVisible('#b_results', 15000)
        .assert.containsText('#b_results', 'Nightwatch')
        .end();
    }
};

Log - actual error

 message: 'ReferenceError: R is not defined\nBuild info: version: \'3.4.0\', revision: \'unknown
\', time: \'unknown\'\nSystem info: host: \'WASWL-C029329\', ip: \'10.172.11.54\', os.name: \'Window
s 10\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_111\'\nDriver info: org.open
qa.selenium.firefox.FirefoxDriver\nCapabilities [{moz:profile=C:\\Users\\djun642\\AppData\\Local\\Te
mp\\rust_mozprofile.xqwQclnwJBsC, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script
=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=fa
lse, acceptInsecureCerts=false, browserVersion=55.0, platformVersion=10.0, moz:processID=11484.0, br
owserName=firefox, javascriptEnabled=true, platformName=windows_nt}]\nSession ID: 715a6352-98b0-46f8
-a33e-85b8ff4fc71f',

Logs

Running:  Demo test Bing
INFO Request: POST /wd/hub/session
 - data:  {"desiredCapabilities":{"browserName":"firefox","javascriptEnabled":true,"acceptSslCerts":
true,"platform":"ANY","marionette":true,"name":"Sum Test"}}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":149}
INFO Response 200 POST /wd/hub/session (4907ms) { state: null,
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 1155870193,
  value: 
   { 'moz:profile': 'C:\\Users\\djun642\\AppData\\Local\\Temp\\rust_mozprofile.xqwQclnwJBsC',
     rotatable: false,
     timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
     pageLoadStrategy: 'normal',
     platform: 'ANY',
     specificationLevel: 0,
     'moz:accessibilityChecks': false,
     'webdriver.remote.sessionid': '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
     acceptInsecureCerts: false,
     browserVersion: '55.0',
     platformVersion: '10.0',
     'moz:processID': 11484,
     browserName: 'firefox',
     takesScreenshot: true,
     javascriptEnabled: true,
     platformName: 'windows_nt',
     cssSelectorsEnabled: true },
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
INFO Got sessionId from selenium 4b5b94c6-c070-4182-8a15-14ea8b6c3b4c
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/url
 - data:  {"url":"https://www.bing.com"}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":30}
INFO Response 200 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/url (2337ms) { state: 's
uccess',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 747307950,
  value: null,
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
LOG     → Completed command url (2386 ms)
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/elements
 - data:  {"using":"css selector","value":"body"}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":39}
INFO Response 200 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/elements (83ms) { state:
 'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 1437452163,
  value: [ { ELEMENT: '0' } ],
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
INFO Request: GET /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/0/displayed
 - data:
 - headers:  {"Accept":"application/json"}
INFO Response 200 GET /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/0/displayed (145m
s) { state: 'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 660239179,
  value: true,
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
 ✔ Element <body> was visible after 382 milliseconds.
LOG     → Completed command waitForElementVisible (388 ms)
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/execute
 - data:  {"script":"var passedArgs = Array.prototype.slice.call(arguments,0); return function (u,i)
 {/* jshint browser:true */return (function(d){var e=d.createElement('script');var m=d.getElementsBy
TagName('head')[0];e.src=u;if(i){e.id=i;}m.appendChild(e);return e;})(document);}.apply(window, pass
edArgs);","args":["https://cdnjs.cloudflare.com/ajax/libs/ramda/0.24.1/ramda.min.js"]}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":376}
INFO Response 200 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/execute (210ms) { state:
 'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 1485816382,
  value: { ELEMENT: '1' },
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
LOG     → Completed command execute (254 ms)
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/execute
 - data:  {"script":"var passedArgs = Array.prototype.slice.call(arguments,0); return function (data
) {\n            return R.add(1, 2);\n        }.apply(window, passedArgs);","args":[]}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":176}
ERROR Response 500 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/execute (807ms) { state
: 'javascript error',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 1145051842,
  value:
   { additionalInformation: '\nDriver info: org.openqa.selenium.firefox.FirefoxDriver\nCapabilities
[{moz:profile=C:\\Users\\djun642\\AppData\\Local\\Temp\\rust_mozprofile.xqwQclnwJBsC, rotatable=fals
e, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY
, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=5
5.0, platformVersion=10.0, moz:processID=11484.0, browserName=firefox, javascriptEnabled=true, platf
ormName=windows_nt}]\nSession ID: 715a6352-98b0-46f8-a33e-85b8ff4fc71f',
     localizedMessage: 'ReferenceError: R is not defined\nBuild info: version: \'3.4.0\', revision:
\'unknown\', time: \'unknown\'\nSystem info: host: \'WASWL-C029329\', ip: \'10.172.11.54\', os.name:
 \'Windows 10\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_111\'\nDriver info:
 org.openqa.selenium.firefox.FirefoxDriver\nCapabilities [{moz:profile=C:\\Users\\djun642\\AppData\\
Local\\Temp\\rust_mozprofile.xqwQclnwJBsC, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.
0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibility
Checks=false, acceptInsecureCerts=false, browserVersion=55.0, platformVersion=10.0, moz:processID=11
484.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt}]\nSession ID: 715a6352-
98b0-46f8-a33e-85b8ff4fc71f',
     systemInformation: 'System info: host: \'WASWL-C029329\', ip: \'10.172.11.54\', os.name: \'Wind
ows 10\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_111\'',
     supportUrl: null,
     cause: null,
     suppressed: [],
     message: 'ReferenceError: R is not defined\nBuild info: version: \'3.4.0\', revision: \'unknown
\', time: \'unknown\'\nSystem info: host: \'WASWL-C029329\', ip: \'10.172.11.54\', os.name: \'Window
s 10\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_111\'\nDriver info: org.open
qa.selenium.firefox.FirefoxDriver\nCapabilities [{moz:profile=C:\\Users\\djun642\\AppData\\Local\\Te
mp\\rust_mozprofile.xqwQclnwJBsC, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script
=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=fa
lse, acceptInsecureCerts=false, browserVersion=55.0, platformVersion=10.0, moz:processID=11484.0, br
owserName=firefox, javascriptEnabled=true, platformName=windows_nt}]\nSession ID: 715a6352-98b0-46f8
-a33e-85b8ff4fc71f',
     hCode: 204764015,
     class: 'org.openqa.selenium.JavascriptException',
     buildInformation:
      { buildTime: 'unknown',
        buildRevision: 'unknown',
        releaseLabel: '3.4.0',
        hCode: 924728501,
        class: 'org.openqa.selenium.internal.BuildInfo' } },
  class: 'org.openqa.selenium.remote.Response',
  status: 17 }
{ additionalInformation: '\nDriver info: org.openqa.selenium.firefox.FirefoxDriver\nCapabilities [{m
oz:profile=C:\\Users\\djun642\\AppData\\Local\\Temp\\rust_mozprofile.xqwQclnwJBsC, rotatable=false,
timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, s
pecificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=55.0
, platformVersion=10.0, moz:processID=11484.0, browserName=firefox, javascriptEnabled=true, platform
Name=windows_nt}]\nSession ID: 715a6352-98b0-46f8-a33e-85b8ff4fc71f',
  localizedMessage: 'ReferenceError: R is not defined\nBuild info: version: \'3.4.0\', revision: \'u
nknown\', time: \'unknown\'\nSystem info: host: \'WASWL-C029329\', ip: \'10.172.11.54\', os.name: \'
Windows 10\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_111\'\nDriver info: or
g.openqa.selenium.firefox.FirefoxDriver\nCapabilities [{moz:profile=C:\\Users\\djun642\\AppData\\Loc
al\\Temp\\rust_mozprofile.xqwQclnwJBsC, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0,
script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChe
cks=false, acceptInsecureCerts=false, browserVersion=55.0, platformVersion=10.0, moz:processID=11484
.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt}]\nSession ID: 715a6352-98b
0-46f8-a33e-85b8ff4fc71f',
  systemInformation: 'System info: host: \'WASWL-C029329\', ip: \'10.172.11.54\', os.name: \'Windows
 10\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_111\'',
  supportUrl: null,
  cause: null,
  suppressed: [],
  message: 'ReferenceError: R is not defined\nBuild info: version: \'3.4.0\', revision: \'unknown\',
 time: \'unknown\'\nSystem info: host: \'WASWL-C029329\', ip: \'10.172.11.54\', os.name: \'Windows 1
0\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_111\'\nDriver info: org.openqa.
selenium.firefox.FirefoxDriver\nCapabilities [{moz:profile=C:\\Users\\djun642\\AppData\\Local\\Temp\
\rust_mozprofile.xqwQclnwJBsC, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30
000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false
, acceptInsecureCerts=false, browserVersion=55.0, platformVersion=10.0, moz:processID=11484.0, brows
erName=firefox, javascriptEnabled=true, platformName=windows_nt}]\nSession ID: 715a6352-98b0-46f8-a3
3e-85b8ff4fc71f',
  hCode: 204764015,
  class: 'org.openqa.selenium.JavascriptException',
  buildInformation:
   { buildTime: 'unknown',
     buildRevision: 'unknown',
     releaseLabel: '3.4.0',
     hCode: 924728501,
     class: 'org.openqa.selenium.internal.BuildInfo' } }
LOG     → Completed command execute (897 ms)
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element
 - data:  {"using":"css selector","value":"input[type=search]"}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":53}
INFO Response 200 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element (17ms) { state:
'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 1004314713,
  value: { ELEMENT: '2' },
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/2/value
 - data:  {"value":["n","i","g","h","t","w","a","t","c","h"]}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":51}
INFO Response 200 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/2/value (65ms) {
 state: 'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 98120000,
  value: null,
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
LOG     → Completed command setValue (103 ms)
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element
 - data:  {"using":"css selector","value":"input[name=go]"}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":49}
INFO Response 200 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element (17ms) { state:
'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 988269001,
  value: { ELEMENT: '3' },
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/3/click
 - data:
 - headers:  {"Content-Length":0}
INFO Response 200 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/3/click (877ms)
{ state: 'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 1990140342,
  value: null,
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
LOG     → Completed command click (916 ms)
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/elements
 - data:  {"using":"css selector","value":"#b_results"}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":45}
INFO Response 200 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/elements (30ms) { state:
 'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 779998977,
  value: [ { ELEMENT: '4' } ],
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
INFO Request: GET /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/4/displayed
 - data:
 - headers:  {"Accept":"application/json"}
INFO Response 200 GET /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/4/displayed (218m
s) { state: 'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 1338712762,
  value: true,
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
 ✔ Element <#b_results> was visible after 427 milliseconds.
LOG     → Completed command waitForElementVisible (496 ms)
INFO Request: POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element
 - data:  {"using":"css selector","value":"#b_results"}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":45}
INFO Response 200 POST /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element (244ms) { state:
 'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 408631696,
  value: { ELEMENT: '4' },
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
INFO Request: GET /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/4/text
 - data:
 - headers:  {"Accept":"application/json"}
INFO Response 200 GET /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c/element/4/text (574ms) {
state: 'success',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 1660870096,
  value: 'Operation Nightwatch – Reducing the Impact of Poverty and ...\nseattlenightwatch.org\nOper
ation Nightwatch reduces the impact of poverty and homelessness, in keeping with Jesus’ teaching to
love our neighbors.\nHistory · Need Shelter · Ways to Help · Programs & Services · Donate Financiall
y · Contact Us\nNightwatch - Official Site\nwww.aetv.com/shows/nightwatch\nPolice and fire rescue te
ams encounter unnerving cases on the night shift in Tampa, Florida.\nCast · Nightwatch Season 1 · Ni
ghtwatch - Season 2 · Holly Monteleone · Season 1 - A&E\nImages of nightwatch\nbing.com/images\nSee
more images of nightwatch\nNightwatch (1997) - IMDb\nwww.imdb.com/title/tt0119791\n6.2/10 · 17K rati
ngs · Drama/Horror/Thriller · R\nDirected by Ole Bornedal. With Ewan McGregor, Nick Nolte, Anais Eva
ns, Erich Anderson. A law student, who takes a job as a night watchman at a morgue, begins to ...\nN
ight Watch (2004 film) - Wikipedia\nhttps://en.wikipedia.org/wiki/Night_Watch_(2004_film)\nNight Wat
ch (Russian: Ночной дозор, Nochnoy dozor) is a 2004 Russian urban fantasy supernatural thriller film
 written by Timur Bekmambetov and Laeta ...\nPlot · Cast · Production · Release · "Nochnoi Bazar" fu
n ...\nVideos of nightwatch\nbing.com/videos\n43:11HD\nWhen Work Becomes Family\nA&E\n43:13HD\nCaugh
t You, By Surprise\nA&E\n43:11HD\n100%, Every Time\nA&E\n43:12HD\nFull Moon Rising\nA&E\nSee more vi
deos of nightwatch\nOperation Nightwatch Seattle - Contact Us\nseattlenightwatch.org/contact.htm\nCo
ntact Us : Operation Nightwatch P.O. Box 21181 Seattle, WA 98111 Physical Location: Dispatch Center
& Senior Housing : Administrative Office\nNightwatch Cast | A&E\nwww.aetv.com/shows/nightwatch/cast\
nMeet the cast of Nightwatch on A&E. Get season by season character and cast bios and more only on A
&E.\nNightwatch - Home | Facebook\nhttps://www.facebook.com/Nightwatch\nNightwatch. 186K likes. Offi
cial Nightwatch page Twitter @AETV | Instagram @AETV AETV.tumblr.com http://www.aetv.com/shows/night
watch\nNightwatch - The World\'s First Smart Halter\nwww.nightwatch24.com\nYour Horse Is Never Alone
 With NIGHTWATCH™. Get 24/7 Real-Time Monitoring with the Nightwatch™ Equine Distress & Wellness Mon
itor\nOperation Nightwatch Moves Into Temporary Location in ...\nhttps://www.seattlemet.com/articles
/2017/5/10/operation-nightwatch...\nOperation Nightwatch on Wednesday is moving its night shelter to
 a temporary location—a city-owned building, on 1117 Northeast Boat Street, slated to be demolished
...\nNightwatch - A&E® - Watch Full Episodes\nAd · www.aetv.com\nSign In With Your TV Provider to Wa
tch Every Season of Nightwatch Online Now!\nWatch Full Episodes · Nightwatch Exclusives · Photo Gall
ery\nWatch Monday Night Raw - Begin Your 30 Day Free Trial | hulu.com\nAd · www.hulu.com/30DayFreeTr
ial/MondayNightRaw\nCatch Up with the Latest Episodes or Binge from the Beginning - Only on Hulu!\nF
ind Current Episodes · Live TV Now on Hulu · HBO®, Meet Hulu\nNight Watch at Amazon.com - Low Prices
 on Night Watch.\nAd · www.amazon.com/Night Watch\nLow Prices on Night Watch. Free Shipping on Quali
fied Orders.\nActors: Vladimir Menshov, Alexandra Paul, David Hasselhoff and more\nTry Amazon Prime
· Amazon Kindle\nRelated searches for nightwatch\nnightwatch tv show cancelled\nholly monteleone\nni
ghtwatch new orleans season 3\nnightwatch tv show season 3 premiere\nnightwatch tampa\nnightwatch ta
mpa florida\nis holly monteleone married\nnightwatch season 3 release date\nYour results are persona
lized. Learn more\n1\n2\n3\n4\n5',
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
 ✔ Testing if element <#b_results> contains text: "Nightwatch".
LOG     → Completed command getText (877 ms)
INFO Request: DELETE /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c
 - data:
 - headers:  {"Content-Length":0}
INFO Response 200 DELETE /wd/hub/session/4b5b94c6-c070-4182-8a15-14ea8b6c3b4c (1865ms) { state: 'suc
cess',
  sessionId: '4b5b94c6-c070-4182-8a15-14ea8b6c3b4c',
  hCode: 1703000200,
  value: null,
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
LOG     → Completed command end (1870 ms)
LOG     → Completed command session (1866 ms)
INFO FINISHED

Spec

nightwatch v0.9.16
node v6.11.2
selenium v3.4.0
Windows 10 PRO 1703
beatfactor commented 7 years ago

maybe you can send a pull request then?

jupier commented 7 years ago

Hi @dennyjun !

You should admit that ``ìnjectScript``` is an async function which waits a callback function in third parameter when the command finishes. Did you allready try as follow :

browser
        .url('https://www.bing.com')
        .waitForElementVisible('body', 15000)
        .injectScript('https://cdnjs.cloudflare.com/ajax/libs/ramda/0.24.1/ramda.min.js', () => {
          browser.execute(data => R.add(1, 2), [], (result) => assert.strictEqual(result.value, 3))
        })
dennyjun commented 7 years ago

Hi @ridrum !

The callback function does not check to see if the script has been loaded. It will run after nighwatch runs its execute function inside of injectScript. Puppeteer's addScriptTag function waits until onload has fired and I have not had any issues with that so far. Even if the format you suggested worked, it would mean callback hell for multiple inject scripts. I will send in a PR to address the issue.

jupier commented 7 years ago

@dennyjun You're right ! Nice catch ! That would be a good improvement !

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.