how do you use windowPosition in nightwatch.js? - nightwatch.js

How do I use the windowPosition function in nightwatch.js?
http://nightwatchjs.org/api/windowPosition.html
I want to get the current position of the window browser.

This took me a moment to figure out as well!
client.windowPosition('current', (res) => {
console.log(res.value.x, res.value.y);
});

Related

how to close the current window/tab using cypress

I need to close the tab/window after each test so I can start the next from scratch
describe('theImplementationIamTesting', () => {
after(() => {
// CLOSE THE TAB AFTER THE TEST...
});
});
I am looking a way to close the current tab after the test. I am not talking about closing a child tab/window. I am talking about the initial tab.
In selenium, it will be something like webdriver.close().
I cannot find a single place online, including the cypress website, where it said how to close the tab browser.
Thanks for helping
If you separate the cases in different test files it will close the whole browser and reopen it every time. This is the only way I had found so far and works for me very well to start every case from scratch since sometimes it continues to run unfinished API requests from the first case after the start of the second case.
The downside is you need to make the initial preparation of the system every time and it increases the runtime.
The way I resolved this was to actually add an extra line at the end of each test which would click to navigate to a page from where the other tests could continue, say the 'home page'.
describe('Test Inline Text Entry Interactions', () => {
beforeEach('Log in as CypressEditor', () => {
cy.MockLoginUser('cypressEditor');
cy.visit('http://localhost:4200/homepage');
})
it('should test 1st thing', () => {
//Test something, then...
cy.get('#logo-label').click(); //To navigate back to http://localhost:4200/homepage
});
it('should test the 2nd thing', () => {
//Test something else...
cy.get('#logo-label').click(); //To navigate back to http://localhost:4200/homepage
});
it('should test the 3rd thing', () => {
//Test some more stuff, then...
cy.get('#logo-label').click(); //this might not be necessary since it's the last one.
});
For me this ensured that each test could finish and continue with the next.

Nativescript-Vue close modal after timeout

I am opening a modal component from a Nativescript-Vue function which opens fine
this.$showModal(SuccessModal).then(() => { console.log('Modal Closed') });
I can call $modal.close from a button within the modal but getting $modal is undefined if I try to call this from, say, the mounted() hook.
I want the modal to close on its own after a three second timeout rather than the user having to click outside of the modal.
How would I go about this?
When using the traditional syntax for function you loose the current context (this), use arrow functions to avoid that.
setTimeout(() => {
this.$modal.close();
}, 3000);
Or you will have to keep reference to context in a variable
var me = this;
setTimeout(function() {
me.$modal.close();
}, 3000);
Here's a twist on #Manoj's response.
Instead of using an external variable to bind the global this, you could use a .bind() in your native (non-arrow) function if you're inclined to do so, like this:
setTimeout(function() {
this.$modal.close();
}.bind($this), 3000);

Three.js - mtlLoader materials

mtlLoader.load('.mtl_file_path', function (materials) {
materials.preload()
console.log(materials.materials)
objLoader.setMaterials(materials)
objLoader.load('/resource/obj/mycar.obj', function (car) {
do somthing
})
})
This is my code. I want to know my mtl's values.
So, console.log(materials.materials)
console result is
I can see in my brower console, but i don't know how can approach it on code.
I tried
console.log(materials.materials[0])
console.log(materials.materials{"midnight_blue"})
console.log(materials.materials.midnight_blue)
materials.preload()
console.log(materials.materials.midnight_blue)

Multiple on click events on document. Which is better?

Can someone tell me which is the correct/better way to do it?
$(document.body).on("click", "string1", function() {
do function
});
$(document.body).on("click", "string2", function() {
do function
});
OR
$(document.body).on("click", "string1", function() {
do function
}).on("click", "string2", function() {
do function
})
I've been doing the 2nd for a while now and it seems to work fine. But I've also been sceptical about it for some reason. Any advise is appreciated!
In my first opinion,
if you try $(document.body) double time then it will traverse again in DOM which is not good idea. So second example is good to avoid second time traversal in DOM

How do I find out with Mootools if an element is being animated?

I need to be able to detect is an animation is currently happening using Mootools.
Of course if there is a way to detect this with plain old js even better. But I couldn't think of a way to do this without running it every ms and seeing if the styles are changing.
How i'm doing the animation
new Fx.Tween(c.getElement('.is-active'), {
property: 'opacity',
duration: e.options.speed,
onComplete: function () {
this.element
.removeClass("is-active")
.addClass("is-hidden")
.setStyle('display', "")
.setStyle('opacity', "");
}
}).start(0).wait(e.options.speed);
One way that I often use is to check if animation is running with isRunning function:
// constructor
var fx = new Fx.Tween( ....
// later when I want to check if animation is running
if ( fx.isRunning() ) ...

Resources