Not able to open link in new tab using ctrl + mouse click in testcafe - testing

import { fixture, Selector } from 'testcafe';
fixture`Fixture import`.only
.page('https://testcafe.io/documentation/402634/guides');
test('Click a button', async t => {
await t.maximizeWindow()
const ab = Selector('a[href="/documentation/402837/guides/basic-guides/assertions"]')
await t.click(ab, {modifiers: {ctrl:true}})
await t.wait(5000)
});
I'm trying to open a link in new tab using ctrl + click, the testcase was getting pass, not throwing any error but the link is opening in the same tab.

TestCafe does not open new windows using the Ctrl + mouse click combination. The ctrl modifier only sets the ctrlKey property of the MouseEvent to true.
If you want to open a new window, you can use the openWindow method: https://testcafe.io/documentation/402694/reference/test-api/testcontroller/openwindow

Related

Catch URL after click with Cypress (window.location changes)

I would like to know how to capture and read the URL after a click event on an <a> link.
On the onClick event our javascript does some string manipulation of the actual href of the clicked link and then a window.location.href = myNewReplacebleURL is done on the fly. The original href is not necessarily the location you get to after the onClick.
Here is how I started:
describe("Twitter", function() {
it("Should assert that via value is set correctly in JS", function() {
cy.server();
cy.visit(Cypress.config("appUrl") + "/probes/sha/sha-via.html");
cy.get("#v_test ul.share li a")
.click();
});
});
EDIT: What I would like is to catch the URL located at the "Page Load" step.
You should be able to use cy.on to perform your assertions inside the url:changed event callback:
cy.on("url:changed", (newUrl) => {
expect(newUrl).to.contain("?magic=true")
})
You can use thecy.location() command, example:
cy.get("#v_test ul.share li a")
.click();
cy.location('href').should('eq', 'newUrl');
Also, as an alias to the cy.location('href') command you could use cy.url().

App window restore on keypress

In my app I have added a functionality to minimize app window to system tray on keypress (on ESC or Pause/Break buttons press). So when pressing them the window get minimized.
Is there a way to add functionality to restore app window on certain keypress (even if other application will be currently active)?
For example I press Pause and the window is minimized. I press Pause and the app window is restored.
Here is the solution extracted from node-webkit wiki :
// Load native UI library.
var gui = require('nw.gui');
var option = {
key: "Ctrl+Shift+A",
active: function() {
console.log("Global desktop keyboard shortcut: " + this.key + " active.");
},
failed: function(msg) {
// :(, fail to register the |key| or couldn't parse the |key|.
console.log(msg);
}
};
// Create a shortcut with |option|.
var shortcut = new gui.Shortcut(option);
// Register global desktop shortcut, which can work without focus.
gui.App.registerGlobalHotKey(shortcut);
// If register |shortcut| successfully and user struck "Ctrl+Shift+A", |shortcut|
// will get an "active" event.
// You can also add listener to shortcut's active and failed event.
shortcut.on('active', function() {
console.log("Global desktop keyboard shortcut: " + this.key + " active.");
});
shortcut.on('failed', function(msg) {
console.log(msg);
});
// Unregister the global desktop shortcut.
gui.App.unregisterGlobalHotKey(shortcut);
This example show you how to create a global shortcut listener and the different way to listen the event. This also show you how to unregister the shortcut.

callbacks not firing when opening a magnific popup from another one

I currently have a magnific popup and within that popup i have a link that opens another magnific popup. Something along the lines of:
$('.logbook-entry-details').magnificPopup({
type: 'ajax',
closeBtnInside:true,
closeOnBgClick:false,
closeOnContentClick:false,
callbacks: {
beforeOpen: function () {
$.magnificPopup.close();
},
open: function() {
console.log('Popup open has been initiated');
},
beforeClose: function() {
console.log('Popup before close has been initiated');
},
close: function() {
console.log('Popup close has been initiated');
},
afterClose :function() {
console.log('Popup after close has been initiated');
}
}
});
After reading i found that callbacks on the second popup will not be registered until i close the original popup as opening the new one just replaces the content and actually doesn't recreate a new instance.
I am trying to figure out how i could have my link within my popup close the current popup before calling the code to open the new one so it can register my callbacks.
By the way, the reason I am trying to do this is i want to reopen the original popup after closing my new popup. If you happen to have a better solution please let me know.
So just in case someone needs this answered, i had to add the following code to my new popup.
// a button that closes the popup
$('#cancel-logbook-entry-btn').click(function(){
$.magnificPopup.proto.close.call(this);
});
$.magnificPopup.instance.close = function () {
//code to show the original popup
};
And then in the original popup i had to add otherwise it will never close the popup
$.magnificPopup.instance.close = function () {
// "proto" variable holds MagnificPopup class prototype
// The above change that we did to instance is not applied to the prototype,
// which allows us to call parent method:
$.magnificPopup.proto.close.call(this);
};

onMouseOut onMouseLeave event not triggered for context Menu

I am creating a dynamic context menu and as it is expected I would like to menu to be closed when the mouse leaves the menu box. I have used :
var dlg = new dijit.Menu({
onMouseLeave: function(event){
dijit.popup.close(dlg);
}
});
But when i go out side the box nothing happens. If I put same function inside the MenuItems then when I leave the MenuItem box it closes the box.
Any comment?
This would be because the dijit.Menu does not register onMouseLeave on its domNode.
To do this manually, following is all you need: (havent sampled a test though should work)
var myconnects = []
var dlg = new dijit.Menu({
destroy: function() { // for a neat garbage collections, remove listeners
var ch;
while(ch = myconnects.pop()) ch.disconnect();
this.inherited();
}
...
});
myconnects.push(dojo.connect(dlg.domNode, "onmouseleave", dojo.hitch(dlg, function() {
dijit.popup.close(this);
});

dojo.tooltipdialog cancel(X) button missing

dojo tool tip dialog:
how to put cancelbutton(X) in dojo.tooltip dialog.
I am unable to put that X in that dialog
It does not seem that there is a cancel button for the "dijit.TooltipDialog". What you can possibly do is, add a x (cancel button) in the content of the tip dialog and attach onclick event to it.
You may have a global variable 'dialog' and add the cancel button in its content and attach onclick TooltipDIalog hide event to it as follows.
var dialog = new dijit.TooltipDialog({
content: '<p> whatever you want to display</p><br />' + 'x'
});
Or attach an onclick event to the link after the TooltipDialog dom is added to the document as follows.
var dialog = new dijit.TooltipDialog({
content: '<p> whatever you want to display</p><br />' + '<a id="close-dialog" href="#">x</a>',
onShow : function () {
dojo.connect (dojo.byId('close-dialog'), "onclick", function (evt) {
dojo.stopEvent(evt);
dijit.popup.close(dialog);
});
}
});