UAT > How to check the ordering of data in a table using Selenium? - selenium

I need to test that a resulting list is ordered date descending using selenium.
this.Then(/^the list items should be ordered by date descending$/, (arg1): CucumberStepOutput => {
actions
return 'pending';
});
I'm sure this is something that has been done many times by people in the selenium community - I am hoping someone will share best practice.

If anyone is interested in the answer or at least the solution I ended up with see the snippet below.
It's a bit ugly (comment with suggestions to clean up) but works!
this.Then(/^the list items should be in descending$/, (): CucumberStepOutput => {
return new Promise<void>((resolve, reject) => {
let expectedValues = ['value1',
'value2',
'value3'
];
client.elements('.element-class').then(elements => {
let resultDates: Array<string> = [];
elements.value.reduce<Promise<void>>((chain, nextElement) => {
return chain.then(() => {
return client.elementIdText(nextElement.ELEMENT).then(text => {
resultVa.push(text.value);
});
});
}, Promise.resolve()).then(()=>{
JSON.stringify(resultValues).should.equal(JSON.stringify(expectedValues));
resolve();
})
});
});
});

Related

Find all clickable elements using webdriverio

I am new to webdriver io and I want to get all clickable elements using webdriver io and iterate through them. I came across 'browser.findElements' API, but could not get it to work. Can anyone provide me a sample code ?
var assert = require('assert');
var homePage = require("../../pages/home_page");
describe('Keyboard friendly home page', () => {
it('User should be able to navigate using tab',() => {
browser.url(homePage.url);
elements = browser.findElements("div");
clickableElements = [];
elements.forEach(element => {
if (element.isDiplayed() && element.isClickable()) {
clickableElements.push(element);
}
});
clickableElements.array.forEach(element => {
console.log(elemtent.getText() + "is clickable");
});
});
});
There might be two problems with your example:
incorrect use of findElements, see documentation; you can use $$ command where you pass only a selector, no need to pass a location strategy as well
the last forEach loop should look like this:
clickableElements.forEach(element => {
console.log(elemtent.getText() + "is clickable");
});

How to get a collection from firestore using data from another collection in react-Native.....What Am i Doing Wrong?

I have tried searching everywhere, from stackoverflow to GitHub but i can get a solution. I am trying to get list of users by using their userid that I get from a collection of businesses. What Am i doing wrong?
componentWillMount() {
//Loading all the business collections.
firebase.firestore().collection("business").onSnapshot((snapshot) => {
var bizs = [];
snapshot.forEach((bdt) => {
var userdt = [];
//get document id of a certain user in the business collections
firebase.firestore().collection('users').where("userid", "==", bdt.data().userid).get()
.then((snap) => {
snap.forEach(dc => {
//loading details of the user from a specific ID
firebase.firestore().collection("users").doc(dc.id).onSnapshot((udt) => {
userdt.push({
name: udt.data().fullname,
photourl: udt.data().photoURL,
location: bdt.data().location,
openhrs: bdt.data().openHrs,
likes: '20',
reviews: '3002',
call: bdt.data().contacts
});
console.log(userdt); //this one works
})
console.log(userdt); // but this one doesnt diplay anything just []
})
}).catch((dterr) => {
console.log(dterr)
})
});
this.setState({bizdata: bizs,loading: false
});
});
}
I am using react-native and firestore
Put log with some number,
like,
console.log('1',userdt);
console.log('2',userdt);
and check weather which one is appearing first, Maybe '2' is executing before updating the data

Apply filter to API response - vue.js

I have this method to get data from an API, which sends me information of many furniture pieces:
loadPieces() {
this.isLoading = true;
axios.get(this.galleryRoute)
.then(r => {
this.gallery = r.data;
this.isLoading = false;
})
.catch(error => {
this.$nextTick(() => this.loadPieces());
});
console.log(this.galleryRoute);
},
This is a part of the response I get, which represents only one piece:
[[{"id":266,"name":" Tray 7x45x32, white stained ash","thumbnail":{"width":840,"height":840,"urls":{"raw":"http:\/\/localhost:8888\/storage\/9c\/9d\/9c9dadc6-15a2-11e8-a80a-5eaddf2d1b4a.jpeg","small":"http:\/\/localhost:8888\/storage\/9c\/9d\/9c9dadc6-15a2-11e8-a80a-5eaddf2d1b4a#140.jpeg","medium":"http:\/\/localhost:8888\/storage\/9c\/9d\/9c9dadc6-15a2-11e8-a80a-5eaddf2d1b4a#420.jpeg"}}},
Now I want to create a filter so that I can get a specific piece from the JSON object, using it's id. I've tried searching but so far I have no idea how to do this.
Thanks in advance!
Add a computed property which applies the filter to this.gallery:
computed: {
filteredGallery() {
if (!this.gallery) return []; // handle gallery being unset in whatever way
return this.gallery.filter(picture =>
// some reason to show picture
);
}
}
I'm assuming gallery is an array, but you could apply a similar technique to it if it was an object, using e.g. Object.keys(this.gallery).
Then in your template, use filteredGallery instead of gallery.

Custom is Obsolete

I updated a project to the latest version of Fluent Validation and I get a warning:
'AbstractValidator<AccountSignInModel>.Custom(Func<AccountSignInModel, ValidationFailure>)'
is obsolete: 'Use model-level RuleFor(x => x) instead'
When I am using the following code:
When(x => !String.IsNullOrEmpty(x.Password) && !String.IsNullOrEmpty(x.Username), () => {
Custom(x => {
Boolean valid = service.ValidateCredentials(x.Username, x.Password));
if (!valid)
return new ValidationFailure("Credentials", "Authentication failed");
return null;
});
});
I don't know how to convert this into a RuleFor(x => x).
Or is there another alternative to custom?
We decided to use Fluent Validation recently on our application. So I am fairly new to this, figuring stuff as we go forward.
Stumbled upon your issue while searching for a different issue. There are not many resources on this. Thought I would share my thoughts, if it can help you.
Here is what I would do.
public NewCustomValidator(Interface int)
{
CascadeMode = CascadeMode.Continue; // you could use StopOnFirstFailure or Continue
RuleFor(x=> x.UserName).NotEmpty(); // Will return an error if null or empty
RuleFor(x=> x.Password).NotEmpty();
RuleSet("SomeNameHere", () =>
{
CascadeMode = CascadeMode.StopOnFirstFailure;
var isValid = false;
RuleFor(x=> new { x.UserName, x.Password })
.Must((u , p) =>
{
valid = ValidateCredentials(u, p);
return valid;
})
.WithMessage("You can show any message if you want");
RuleFor(x => x.UserName).Must((s) => isValid);
RuleFor(x => x.Password).Must((s) => isValid);
});
}
So, I am basically using your method to define in a Rule Set. You may have to add some code to validate the ruleSet.
var result = validator.Validate(NewCustom, ruleSet: "SomeNameHere");
Disclaimer: This code may not compile. But it will give you an idea on how to approach the problem. If you have better ideas or If you could make the code work, please post the answer. That will help me gain some more knowledge. Thanks.

Making http requests inside a for loop ANGULAR JS 2

I am trying to work with the youtube API.
In order to get the icons for the first nth videos I have to make a request.
I was thinking to make a for loop and inside that loop there would be the request.
The problem with this approach is that I am getting the responses with the wrong order and completely random.
So my question :
is there a way to make a for loop wait for a response? I am also able to work with the RxJS operators but I don't know what I should search for
Thanks in advance
You could leverage the Observable.forJoin method. In this case, the "global" callback will be called when all requests have ended.
Here is a sample:
Observable.forkJoin([
this.http.get('/req1').map(res => res.json()),
this.http.get('/req2').map(res => res.json()),
(...)
]).subscribe(results => {
// Called when all requests have ended
var result1 = results[0];
var result2 = results[1];
(...)
});
In your particular use case, you can leverage in addition the flatMap operator:
this.http.get('/videos').map(res => res.json())
.flatMap(videos => {
return Observable.forkJoin(videos.map((video) => {
return this.http.get(`/video/${video.id}/icon`)
.map(res => res.json());
});
}).subscribe(results => {
// all icons received here
});
So I ended up using something like this.
searchVideo( videoIdArray ) {
let observableBatch = [];
let data;
let i;
let videosTempArray: Array<Video>=[];
for(i=0;i<videoIdArray.length;i++){
let videoTemp: Video= {};
videosTempArray.push(videoTemp);
}
videosTempArray.forEach(( videoTemp, key ) => {
observableBatch.push( this.http.get(BASE_URL_VIDEO + '?part=statistics%2Csnippet' + '&id=' + videoIdArray[key].videoId + '&key=' + API_TOKEN)
.map((res: Response) => {
res.json();
// console.log(key);
data = res.json();
videosTempArray[key].channelId=data.items[0].snippet.channelId;
videosTempArray[key].tags=data.items[0].snippet.tags;
videosTempArray[key].views=data.items[0].statistics.viewCount;
videosTempArray[key].likes=data.items[0].statistics.likeCount;
videosTempArray[key].dislikes=data.items[0].statistics.dislikeCount;
return videosTempArray[key];
}
)
);
});
return Observable.forkJoin(observableBatch);
}
thanks for the help!!!