I tested this:
expect(wrapper.find('.my-element').at(1).find('input[type="checkbox"]').at(1).props().checked).toEqual(true);
expect(wrapper.find('.my-element').at(1).find('input[type="checkbox"]').at(2).props().checked).toEqual(true);
expect(wrapper.find('.my-element').at(1).find('input[type="checkbox"]').at(3).props().checked).toEqual(true);
expect(wrapper.find('.my-element').at(1).find('input[type="checkbox"]').at(4).props().checked).toEqual(true);
And it works, but in another element there might be more than 4, so I want to do something like
expect(wrapper.find('.my-element').at(1).find('input[type="checkbox"]').all().props().checked).toEqual(true);
Or something like that. Do I have to make a loop to test all the checkboxes that match? Or is there some built in?
So I found a way, don't know if it's the best: but I can make
wrapper
.find('.my-element')
.at(1)
.find('input[type="checkbox"]')
.forEach(node => {
expect(node.props().checked).toEqual(true);
});
Related
I've seen quite a few examples of 'schedule' being used like this:
Timer().schedule(1000) {
// code to execute after delay
}
However, when I try to use it like this the function needs me to supply some sort of 'TimerTask' and I haven't seen anything about that.
So my question is how do you properly use schedule?
I would like to write the second code but I'm not sure of the merit of the first code. Would anyone please tell me the advantage of the first code? Also, can I write the code like the second one instead of the first one?
The first sample that I'm not sure of the advantages and I avoid writing this way:
if not users:
abort(401, {"error_message": "user_id is not defined."})
return user_id, custmer_id
The second sample I would like to use
if not users:
return jsonify({"error_message": "user_id is not defined."}), 401
Is there a way in nightwatch to check whether a popup window appears after each click event?
I have a problem that randomly an error message appear and I don't want to write for each click event the same callback function.
I have already tried out the after and afterEach commands in the Global.js but then the commands will only run after the whole test suite.
I also have tried it local within a test file, although it also does not cover all single click events, even though the official website writes "... while beforeEach and afterEach are ran before and after each testcase (test step)"?
Solution I'm looking for:
.waitForElementVisible('selector')
.click('selector')
.click('selector')
Solution I have come up with so far:
.waitForElementVisible('selector')
.click('selector', isPresent)
.click('selector', isPresent)
isPresent as a callback function, which does the checking and close the popup window if it appears.
Is there another way to write a function (with or without after and/or forEach), so that it will be called after each click event or after each command. Thus, I don't have to write the isPresent repetitive code?
You can insert something like this in your page object file:
var popupCommand = {
popupCheck:function(){
return this.waitForElementVisible('selector', 5000)
.click('selector', isPresent)
.click('selector', isPresent)
},
module.exports = {
commands:[popupCommand],
elements:{
firstElement: {selector: 'xpath',locateStrategy: 'xpath'},
secondElement: {selector: 'css'},
}
}
Where 'popupCommand' will be the name of your page object file, for example 'Popup'. And also you will have to insert your isPresent callback function here so you can use it.
I did my best to explain you as much as possible what and how to do that :)
you should yse .switchWindow() method.
Why don't you write your own custom command specific for that case, so that way you will avoid repetitive code?
In Mongoose, I've never actually seen an example of setting multiple Mongoose plugins on a schema.
All I ever see is
schema.plugin(mongooseSearchPlugin);
How does one go about adding another plugin to that? e.g. mongoosePaginatePlugin?
Unfortunately mongoose doesn't support initializing multiple plugins at once. So the only option is to call schema.plugin(...) multiple times.
You can can call the function multiple times to initialize all your plugins like this:
schema.plugin(mongooseSearchPlugin);
schema.plugin(mongoosePaginatePlugin);
Alternatively, if you store your functions in an iterable (something like an array) you can just iterate over each item and initialize it that way. Something like this:
const myPlugins = [ mongooseSearchPlugin, mongoosePaginatePlugin ];
myPlugins.forEach(plugin => schema.plugin(plugin));
// Or you can you block style
myPlugins.forEach((plugin) => {
schema.plugin(plugin);
});
Depending on how many plugins you're using this might make your code shorter. Ultimately it's a styling choice.
Hope this explanation helped.
Simply call schema.plugin multiple times
I want to simply "click" on a link using Capybara and Cucumber. I have an element that looks like this:
<a class="to-right" id="create-account-link" href="https://somewebsite.com/">Create account</a> //url is different when I test it
I tried the following two methods in my step definition:
page.find('[#id=create-account-link]').click //works
AND
page.find('#create-account-link').click //doesn't work
I would like to find out why the latter doesn't work. Any idea?
I solved it by putting
Capybara.default_wait_time = 5
in my hooks.rb file. It usually waits for two seconds, and apparently the xpath reference is quicker than the other one.