TestCafe: How to use disableMultipleWindows inside "test" function? - testing

I want to disable multiple windows on a specific test only. And I found this option "disableMultipleWindows". But how to use this option inside the test function?
test('test', async t => {
// How to apply this option or similar inside this function?
});
Thanks.

The --disableMultipleWindows option is applied to the set of tests and cannot be applied to a single test or fixture.
Could you please elaborate on why you need to disable this functionality only for a specific test?

Related

In TestCafe Studio, how can I import/reference selectors/functions/custom scripts defined in one fixture into another?

If I define a selector or function in one test, can I access it in another test or a test in another file/fixture? Similarly, is there a way to implement page models and for tests to use selectors defined within page?
TestCafe Studio does not allow sharing selectors and functions defined via the "Define Element Selector" and "Define Function" actions in codeless testing. However, you can import selectors using the Run TestCafe Script action.
For example:

What is the hook for the list of products?

I need a hook that I can't find in the documentation, but logically it should exist.
In my module, I need to add some html in category page (or search results page) after the tile with the products but before pagination.
Which hook is best to use?
There is no default hook for your goal, but you can create your own one and use it within your module. The inconvenience is that you will be able to use it only in modified themes or you will need to add it manually to all new ones. To create the desirable hook you need to put
{hook h='displayYourHook' info=$someData}
in the top of your_theme/templates/catalog/_partials/products-top.tpl
and then just use it like a default hook within your module
public function hookDisplayYourHook($params)
{
// $params can be some information. ID of category for example
do all necessary stuff here
}
and also do not forget to register your hook during the module installation
public function install()
{
....
&& $this->registerHook('addproduct')
....
}
Also, I presume that you use prestashop 1.7.* if not - some code can be different

How to override v-on:click in vue for logging purposes

Looking to implement some logging with the purpose of generating some usage statistics for a web application written with Vue.
I want to avoid writing an explicit 'log' statement within or with every 'on click' callback.
Is it possible to wrap/override the v-on:click directive to first perform logging, then execute the callback?
As far as I know it is not possible to do it for all v-on:clicks at the same time. As the event handlers are connected to the specific elements you would need to do it for every element separately.
Instead you can add an eventlistener for click events like this:
window.addEventListener('click', e => console.log(e))
or like this
document.onclick = e => console.log(e)
Note that this will log every single click, even if it's not on an element with v-on. The event here gives you the source element that was clicked, that you might be able to use to define if the click is relevant for your logging or not.
This previous post could work for you:
Extend vueJs directive v-on:click
A wrapper component for you click event elements.

Load options on the first open of the Async drop down menu

When I provide loadOptions to an Async control it loads options on mount.
If I pass autoload={false} then it doesn't load options neither on mount nor on open. But it loads options on the first close (or type, or blur).
If I pass onCloseResetsInput={false} then it doesn't load options until I type something. (showing "Type to search" in the menu)
Async provides onOpen handler, but I didn't find the way to use it in this situation. (and react-select#2.0.0-alpha.2 doesn't have it)
So the user needs to type a character, then delete it, to see the full list of options.
How can this be avoided?
Example sandbox: https://codesandbox.io/s/mjkmowr91j
Solution demo: https://codesandbox.io/s/o51yw14l59
I used the Async options loaded externally section from the react-select repo.
We start by loading the options on the Select's onFocus and also set the state to isLoading: true. When we receive the options we save them in the state and render them in the options.
I also keep track of optionsLoaded so that only on the first focus do we trigger the call to get options.
In our use case, we have several of these select inputs on a single page, all async, so the requests to the server will pile up, and are completely unnecessary in a lot of cases (users won't even bother clicking).
I found a workaround for this issue that'll work for my use case on 2.0.0-beta.6:
Include defaultOptions
Add 2 members to your class that will store the resolve/reject methods for the promise.
In your loadOptions function, check if the input is '', if so, create a new promise, and store the values of resolve/reject within your class members, and return that promise. Otherwise, just return the promise normally to get your results.
Add an onFocus handler, and within it call the function to get your results, but also add .then and .catch callbacks passing the resolve and reject functions you stored previously.
Essentially, this makes react-select think you're working on getting the results with a long-running promise, but you don't actually even try to load the values until the field is selected.
I'm not 100% positive there aren't any negative side effects as I just wrote this, but it seems like a good place to start.
Hope this helps someone. I may submit a feature request for this.
In order to load options when user focus first time, set defaultOptions={true}
Thanks, Alexei Darmin for the solution, I was struggling with this... while testing it I converted the solution to a react functional component and added real API fetching.
Here is a working demo, I hope it helps someone

Using OR with Selenium.Click - is this possible?

There is an image and a link on this webpage. Clicking on either of them does the same job. I was wondering if there is an option of including OR in Selenium.Click. Something like:
Selenium.Click("image") OR Selenium.Click("link");
Selenium doesn't offer OR condition. If the requirement is to click on either of the locators depending on which one is available, then you can easily create a custom method
This is written in JAVA, you can change it to your programming language
public void ClickOnAvailableLocator(String locator1, String locator2)
{
if(selenium.isVisible(locator1)
selenium.Click(locator1);
else
selenium.Click(locator2);
}
No, if you need to test both routes I would suggest two tests.