-
Notifications
You must be signed in to change notification settings - Fork 98
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
Should include example for use with Selenium #45
Comments
Hello ORESoftware, I am taking help of your above mentioned code to get Client Side JS coverage.I am using Istanbul for it. But when I try to execute this line : 'driver.executeScript("return window.coverage;")', I get following error :
It seems Node doesn't support 'window' instead there is something called 'global' for Node.But when I try to use 'global', I get following error :
Can you please help me out here? I am new to Javascriot world ( & to be precise to the Coding world, as I am a QA) so it's highely likely that I might be missing out something very silly here. Thanks |
I can try to help...first this article might help: You want to use window not global, because that script is executing in the browser. Looks like I am using a different webdriver package.
So try using that installation. then in a bash script, I do this: # start-selenium.sh
cd $(dirname "$0")
./node_modules/.bin/webdriver-manager update
./node_modules/.bin/webdriver-manager start try using that, and let me know if it works. If not, we try more things. Make sure to make the script executable, with
then you can execute the script like so
|
Hey @ORESoftware @gotwarlost, After I include 'webdriver-manager' , I get following error :
Any leads here? Also when I try to follow https://medium.com/@the1mills/front-end-javascript-test-coverage-with-istanbul-selenium-4b2be44e3e98 , I get following error while running my test :
Actually my Node is not able to recognize following keywords : What all libraries do i need to install for above keywords to work ? I did npm install for above mentioned libraries & used in my scripts like (var async = require('asyncawait/async'); |
Hey @ORESoftware @gotwarlost , I managed to tweak the scripts so that I can avoid keywords like await,after,let etc.Following is my code now : My Server :
POST script to server :
My Test :
I have instrumented my code as per the command mentioned in the article & injecting it in sample.html. When I try to run my test , my page is loaded but no coverage data is reported :
What could be the possible reason for this output ? Variable 'window__coverage__' is properly getting populated in the browser & it is getting returned to the object in the script. |
Use NVM to upgrade to a newer version of Node.js You should use version 8 if possible. Try using the original code, and then let me know if you still have problems. e.g.: the above line should be running in Node.js. |
I am running Node Version 8.1.2 (ran latest Node.js JAR file.Shall I update using NVM ? Will it make any difference?) & I am running 'browser.get('file:///Users/kapaga/Desktop/sample.html');' in Node.js only. |
Reinstalled latest version of Node (8.1.2) using NVM & used original code but still node is not able to identify the keywords like cb,after,let etc (as mentioned in my previous comment). Can there be any ES compatibility issue here? Can you use the code which I have pasted above to run a sample test on you local so that if it runs on your local then I can try to replicate your different Library versions on my local? |
are you sure you are using node version 8? what happens when you run
at the command line? make sure you do
and to make 8 your default version, there's a special nvm command for that |
When I do |
Is it your IDE that cannot identify the keywords or the actually node.js runtime? what is the error that you get? |
I get following error :
It's Node.js runtime which cannot identify the keywords. |
You are getting closer. Ok, so There are a lot of moving pieces here. First install Mocha:
Create this simple file: // bar.js
describe('foo', function(){
before('get home',function(){
return browser.get(xxx); // fix this with the right url, this returns a promise
});
it('simple test', function(){
// make some call to selenium to do some actions in your front-end code
});
after('load coverage', function(){
return driver.switchTo().defaultContent().then(function(){
return driver.executeScript('return window.__coverage__;');
}).then(function(obj){
// must return a promise
return postTheDataToYourServerRunningIstanbulMiddleWare(obj);
});
});
}); then run:
mocha will load the global variables into the environment. You probably will have a few more problems but we can work through them. The before/after/it hooks in Mocha (and all similar libraries) will handle promises returned from the callback. At the end I would like to ask you to choose to use Suman instead of Mocha :) Note that the after hook above could be re-written as: after('load coverage', async function(){
await driver.switchTo().defaultContent().then(function(){
let obj = await driver.executeScript('return window.__coverage__;');
return postTheDataToYourServerRunningIstanbulMiddleWare(obj);
}); async/await is a native wrapper around promises + generators. note that for this to work, either way,
must return a promise. |
Sure.Let me try it. |
Finally I am able to see coverage report using following code :
Thanks a ton for your help & guidance. :) :) 👍 But when I try to use code mentioned here : https://medium.com/@the1mills/front-end-javascript-test-coverage-with-istanbul-selenium-4b2be44e3e98 , I get following error :
Any lead here? |
|
Sure. Thanks a lot. :) |
Np at all...if you think I know a thing or two, definitely star this repo https://github.com/sumanjs/suman when I release that project it's gonna be so huge |
by the way, in your code above, you want to do:
this returns the promise to the caller, so the caller can wait for the promise to resolve before shutting down the process. |
I think this example is very good:
gotwarlost/istanbul#132
specifically this line is very important to know:
driver.executeScript("return window.__coverage__;")
Perhaps include something like this in the readme?
The text was updated successfully, but these errors were encountered: