NightmareJS without closing the browser - node.js

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.

Related

Is it possible to continue working in Revit while running a python script in pyrevit?

When running Revitpythonshell or running a python script with XAML gui I am unable to work in Revit until closing Revitpythonshell or the python gui.
Is there a way to keep Revit from becoming inaccessible like this?
I would like to keep my script open to continually use while I work.
You have a couple of options here depending on what your script is trying to do:
pyRevit has a 'non-modal' console that keeps Revit accessible.
Pythons threading module could be what youre looking for. You can automate alot of tasks in the background as you continue working, with one big caveat: Revit is a single-core program, so if you touch the database / API from another thread - Revit will crash.
You can start a process on a thread, then close the console. Your thread will continue to run - you just have to use winforms or another UI tool to let you know where the thread is up to. I use this to automate non-Database tasks that take 30-45 mins, while continuing to work in Revit.
If you need to keep accessing the Revit Database / API from your script, Id recommend making a simple UI and get it talking to an ExternalEvent in Revit. Here is a fantastic example of using a form with ExternalEvent by Cyril Waechter: pyRevit WPF non-modal trouble

Vimscript function calls from terminal emulator

I have Language server client (vim-lsc) installed as a plugin in neovim. This client interacts with a language server for couple of languages, like python or R, and provides features like autocomplete, variable renaming etc...
One feature I want to use is the code execution, in which case you can select the part of the code and then send it to the LSP server for evaluation and get the response for it. I can do a similar thing if I create a terminal emulator "term://python" and copy paste the code there, but in this way there are two "servers" running, one via the LSP server and other from the terminal, similar to what vim-matlab does.
I was hoping to be able to do both with just one instance of python or R or MATLAb running. If there is a way to send the typed "command" in the terminal emulator to the LSP server via the vim-lsc plugin, then the job can be done with just one instance running.
I also thought of making a vimscript which creates a buffer that emulates terminal (like how Conque or vim-terminal do) and then capture and pass the commands via that script. Although, I was not able to figure out how those plugin made the prompt and command output non-modifiable but keeping the current typed command by the user modifiable.
My reason for preferring the LSP route and not opting for plugins like vimterm is that they don't provide various features like autocomplete and refactoring.
Any suggestions would be welcome. Thanks.
EDIT: I would like to clarify that as of now I don't think vim-lsc has the capability to send the executeCommand request. I wrote a small vimscript (sepatate code) which is able to do that. I plan to submit a pull-request in time and have the feature available in vim-lsc, hence the inclusion of vim-lsc in the description. Apologies for the confusion.
If it's part of the LSP protocol, and you can indeed send the code to the LSP server for execution, then it's not one that vim-lsc has implemented; I can't find it in the helpfile. Best thing you can do is search on the issue page and/or post about the feature yourself.

Checking what methods were invoked during execution typescript on node js server (debugging nodejs)

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.

Protractor : use browser or browser.driver methods?

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.

Can I use PhantomJS with Cucumber-js

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) ;)

Resources