Find whether the JS is completed executing - webdriver-io

I am new to webdriverio. In our website, I'm interested to find the whether a JS is completed executing.
For ex: there is file.js which is loaded. This file.js fires an api call. The API call returns with a response. The file.js consume this response and modifies the DOM.
I want to check programmatically if this whole process of JS firing an API, consuming the response and modifying the DOM is completed using WebDriver IO.
Kindly help.

Related

HTML page is causing error in JMeter even if status is green

HTML page is causing error in JMeter even if status is green , why this error is coming
As per JMeter Project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
the Window interface is something browser-specific hence JMeter cannot execute the request properly.
You need to perform manual correlation of the dynamic parameters to replicate browser's behaviour, this way you should stop seeing errors, at least ViewState parameter needs to be extracted from the previous response and passed to the next request, see primefaces-jmeter-test.jmx example test plan for details.

In TestCafe Is possibile to register xhr and use as mocking (automocking)

I'm using testCafe for my functional test.
My project used a lot of XHR request and I don't want to waste my time to generate each single mock.
Exists an automocker like this: https://github.com/scottschafer/cypressautomocker for testcafe?
TestCafe does not provide the described functionality out of the box. However, you can use the combination of RequestLogger and RequestMock
The idea is in that you can create a JSON file with request results at the first run using the RequestLogger.
Then, based on results of the first run, you can configure your RequestMock object to respond with the results from the file for all consequent requests.

a wait that stops the test till nothing is happening in the web page anymore

I am using Java and Selenium to write a test. Many times in my test i have to wait till the page or some part of it loads something. I want to wait till the load is finished. I found these two:
1) pageLoadTimeout
2) setScriptTimeout
But I don't know the exact difference between them or even if they are what I need.
The document says:
setScriptTimeout: Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.
and
pageLoadTimeout: Sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.
but I don't really get it.
what I need is a wait that stops the test till nothing is happening in the web page anymore.
Define "nothing is happening in the web page." Now define it in such a way that will satisfy every web page ever created, or that ever will be created. Did your definition include that no more network traffic is coming over the wire? Did your definition include that the onload event has fired? How about document.readyState returning a value meaning "complete?" Did you take JavaScript execution into account? How about JavaScript scheduled using window.setTimeout()? WebSockets? Service Workers? What about <frame> or <iframe> elements?
Now you know why WebDriver doesn't have a "wait for page complete" type of wait. The items mentioned above don't even begin to scratch the surface of the list of things a user could legitimately use in a definition of "nothing is happening on the page anymore." The correct approach would be to wait for the element you want to interact with on the next page to be available in the DOM. The WebDriverWait class is ideally suited for exactly this.

How is XHR a viable alternative to asynchronous module definition?

I'm learning about the case for asynchronous module definition (AMD) from here but am not quite clear about the below:
It is tempting to use XMLHttpRequest (XHR) to load the scripts. If XHR
is used, then we can massage the text above -- we can do a regexp to
find require() calls, make sure we load those scripts, then use eval()
or script elements that have their body text set to the text of the
script loaded via XHR.
XHR is using ajax or something to make a call to grab a resource from the database, correct? What does the eval() or script elements have to do with this? An example would be very helpful
That part of RequireJS' documentation is explaining why using XHR rather than doing what RequireJS does is problematic.
XHR is using ajax or something to make a call to grab a resource from the database, correct?
XHR is what allows you to make an Ajax call. jQuery's $.ajax for instance creates an XHR instance for you and uses it to perform the query. How the server responds depends on how the server is designed. Most of the servers I've developed won't use a database to answer a request made to a URL that corresponds to a JavaScript file. The file is just read from the file system and sent back to the client.
What does the eval() or script elements have to do with this?
Once the request is over, what you have is a string that contains JavaScript. You've fetched the code of your module but presumably you also want to execute it. eval is one way to do it but it has the disadvantages mentioned in the documentation. Another way to do it would be to create a script element whose body is the code you've fetched, and then insert this script in the DOM but this also has issues, as explained in the documentation you refer to.

how can i call a worklight's SQL adapter on the load event of a html page

I have an existing SQL adapter used to get some data from the DB server, a simple query that returns a language.
I want to call it from an HTML page, to display the page in the language returned from the adapter.
I'm trying to call it before the dojoConfig object is created because it sets the locale, that then it's used by dojo to do the internationalization work. Is there a way to call the adapter synchronously so it executes before the dojo configuration happens? I mean to catch either the success or failure response before a dojoConfig object is created.
How could i invoke it?
Worklight APIs can only be used once wlCommonInit has been called.
If you can delay/postpone/set dojoConfig on the success callback of the adapter call, then this may be your way out of the problem you have encountered.