When using protractor, the global variable browser appears to have all the functionality of browser.driver.
I am specifically asking this because I am not sure whether to use browser.wait or browser.driver.wait as they both appear to be the same method, and I also saw that a lot of the browser.driver methods are available in browser (if not all).
So what is the recommended way to call those methods browser.method or browser.driver.method?
In theory the distinction is simple: If this is an Angular application under test - use browser, otherwise - browser.driver.
A little bit more to the story:
Protractor wraps around WebDriverJS - javascript selenium bindings - as a part of that it wraps the selenium driver object itself leaving you the access to the pure WebDriverJS driver via browser.driver.
There are though other takeaways, please take a look at this related threads:
Protractor browser.driver.getCurrentUrl vs browser.getCurrentUrl
browser.driver vs browser. Which one to use?
Some browser methods are the same...
The browser object is made up by composition of WebDriver methods and Protractor specific methods. So methods like sleep, wait, and getCurrentUrl are copied over from WebDriver (see the browser.ts). So should you use browser or browser.driver? Well, if it is listed in the link above, they are the exact same thing.
Some browser methods are not...
However, not every method is just copied over. For methods like get, the browser is implemented differently in Protractor vs selenium-webdriver. For Angular pages, you should use browser.get. This will wait for Angular to be stable before moving on to other commands before moving onto other commands.
When in doubt, check out the documentation
So when you navigate to protractortest.org/#/api, you will see a list of browser methods that are Protractor specific and "inherited from webdriver.WebDriver". The methods that follow "inherited from webdriver.WebDriver" are the same method if you decide to use browser or browser.driver.
Related
I am developer with poor experience, however with strong academic CS background.
So please be patient where I am wrong somewhere.
As far I know, typescript can be executed on JS server and it works in this way in my case. Namely, I execute e2e tests with protactor (angular test framework).
I would like to debug it and check what methods was called during such execution on nodejs. To give you more details, I would like if (and possibly parameters) was invoked
waitForAngular(rootSelector, callback) method.
I know that it is possible to dump a variety of traces and debugging info from JVM, however I have no idea how can I do it with nodejs in my specific case.
Could you help me, please?
Around where you have your calls to waitForAngular (or any other code that you want to check), add a console.trace(), which will display a stack trace at that exact line of code.
You can read more about console.trace() and other console API methods at this document by the Chrome project (node.js uses the JS engine that Chrome uses): https://developers.google.com/web/tools/chrome-devtools/console/api#trace
You can sprinkle debugger statements in your code to stop execution which will allow you to step through your code. Similarly, you could start your Node process with the --inspect-brk argument to use Chrome DevTools to step through your code.
I'm currently working on an IPFS/Ethereum dapp in Muon.
Because i need Metamask i started with this Boilerplate: https://github.com/SwapyNetwork/electron-metamask-boilerplate
Everything is working fine so far.
However i can not use require('anything') in the renderer process or in html script tags. (See below)
There seems to be a problem with the boilerplate code but i can't find it.
Or is node code in renderer not supported in Muon?
My only change in testing is setting node-integration explicitly to true and
inserting require('fs') in index.js. (i installed fs of course).
I tried many different solutions from stackoverflow and other sites but couldn't find a solution yet.
Error Message
Thank you
As per the muon's github repo:
Some of Muons goals include:
Use the Chromium source directly (eliminating electron's copy of chrome_src) with minor patches
make integrating chrome components less painful
faster and more streamlined end-to-end build process (see browser-laptop-bootstrap).
add support for Chrome extensions
add security focused features for the renderer:
remove node completely (from the renderer process)
full sandbox
scriptable window.opener support
As you can see there, muon does not supports node code in the rendered. It is by design for security purpose. Muon may be great for certain applications, but I recommend switching on to electron if you really need to use require in the renderer.
I'm used to PhantomJS and Watir, which both provide a REPL out of the box. The REPL lets me execute automation calls on a currently-running browser.
This is a fun way to make automation scripts because I can watch the effect of each step as I build an automation script.
In fact, I can even write a script that defines methods for opening a browser, performing a log-in, and other common tasks, and then call them as I please from within the generic Node or Ruby REPL.
Can I execute NightmareJS calls without closing the browser (Electron)?
Without closing? Yes - don't call .end().
If you're asking if you could disconnect the IPC - meaning the calling program ends but does not end the Nightmare instance - and then pick up the Nightmare instance again somewhere else, the answer is no.
#393 (packaging Nightmare functions with an existing Electron application) and #593 (covering v3 wants, including one Electron instance for many applications) are related, but I'm not convinced attaching IPC from new calling applications is a great idea.
If you provide more information about what your circumstances are and what you're trying to do, I'll edit this answer to try to help.
Having a REPL is a different question - I will add it to my list of things to look into. It's a good idea.
I've been using Zombie.js with my cucumber-js scripts but having a bit of trouble and can't get my issues resolved as of yet. It's extremely late in my game to switch to a different headless browser, but, if I can't solve my issues in zombie, I might need to make the jump.
However, I can't seem to figure out if I can integrate it into my cucumber-js scripts the way I integrated zombie. PhantomJS seems to be a standalone thing, but I need it to run as a required module.
I've scanned the documentation and can't figure out if I can do this.
Is this possible?
Yes. We created an open source package that allows you to do exactly this, it runs Phantom in GhostDriver mode so it runs without selenium.
https://github.com/xolvio/chimp
You also get synchronous javascript for Webdriver (no callbacks, no promises) ;)
I'm looking for a javascript library that attempts to provide the same simple utilities in both the browser environment AND nodejs (iteration, mapping, maybe control-flow) so that code can more easily be re-used across server and client. I know you can hack out parts of any JS library (YUI, jQuery, ...) and get them to work in both environments, I'm just wondering if it's already been done or standardized.
The closest I've seen is this: https://github.com/kof/sharedjs
But it's incomplete and has some odd stuff. I'm wondering if there is something more polished before I fork and hack.
The underscore library was built to add more functional programming to jquery, things like mapping, and also templating.
Because it doesn't rely on the DOM (it leaves that to jquery) it functions well in node.
The RightJS link library has a server build link that has node.js in mind.
From the download page:
RightJS is also available as a server-side library. In this case it contains only the native JavaScript unit extensions and the Class, Observer, Options units along with all the non-DOM utility functions from the Util module.
Our server-side build follows the CommonJS principles and is ready for use with the node.js framework.
Node's GitHub wiki has a list of CommonJS-compatible modules which will run in Node and browsers.
Some of the other modules on that page may also run in a browser environment. For example, the excellent DateJS works fine in Node. (It is available as a NPM.)
Btw, RightJS is also available on NPM