Leaving a memo
customerNameList() {return element.all(by.css("#items")).
all(by.css(".list-item-title"));}
This customerNameList() fetches customer name list data.
step.Then(/^Check sorting$/, (done: Callback)=> {
let sorted = [] , unSorted = [];
let cName = customerViewPage.customerNameList();
cName.map(function(eachName){
return eachName.getText().then(function(unSorted){
return unSorted;
});
}).then(function(unSorted){
let sorted = unSorted.slice();
sorted = sorted.sort(); //sort the array
for(let i = 0; i < sorted.length; i++){
console.log(' Array1 : ' + sorted[i] +' is equals to Array2 : ' + unSorted[i]);
expect(sorted[i]).is.equal(unSorted[i]);
}
done();
});
});Check sorting results.
unSorted[] array will have current customer name list.
sorted[] array is sorting the current customer name list.
compare sorted[] and unSorted[]
if pass then the customer list is sorted properly.
step.Then(/^Check sorting$/, (done: Callback)=> {
let sorted = [] , unSorted = [];
let cName = customerViewPage.customerNameList();
let i = 0;
cName.each(function(eachName){
eachName.getText().then(function(name){
// unSorted[i] = name.toLowerCase();
unSorted[i] = name;
i++;
});
}).then(function(){
sorted = unSorted.slice();
sorted.sort();
for(let i = 0; i < sorted.length; i++){
console.log(' Array1 : ' + sorted[i] +' is equals to Array2 : ' + unSorted[i]);
expect(sorted[i]).is.equal(unSorted[i]);
}
done();
});
});
This step has the same functionality as above.
let statelist:any;
let sortedStatelist:any;
addCustomerPage.state().click().then(()=>{
addCustomerPage.stateDropDownOptions().then(function (actualListOfStates) {
statelist=actualListOfStates.slice();
sortedStatelist=statelist.sort();
// expect(statelist).to.contains(sortedStatelist);
for(let i=0;i<sortedStatelist.length;i++){
expect(statelist[i]).is.equal(sortedStatelist[i]);
}
done();
})
})
Fetch items from dropdown menu and check sorting status.
JavaScript Array slice() Method
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(1, 3);
Orange,Lemon
Definition and Usage
The slice() method returns the selected elements in an array, as a new array object.
The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument.
Note: The original array will not be changed.
'TDD Project > Protractor_Cucumber' 카테고리의 다른 글
[Protractor] Asynchronous Testing with Protractor’s ControlFlow (0) | 2017.05.11 |
---|---|
[Protractor] Protractor-Perf - Performance Testing using Protractor (0) | 2017.05.04 |
[Cucumber] Automation Testing Using Cucumber Tool and Selenium (0) | 2017.04.25 |
Protractor Memo - Javascript sort() case insensitive etc. (0) | 2017.04.13 |
Protractor For Beginners Part 1 (0) | 2017.04.07 |