Using the below script i am working on Pagination using Protractor script where is am seeing "summaryPage" is not defined - protractor

this.getPaginationsize = element.all(by.repeater('page in groupArray track by $index'));
summaryPage.getPaginationsize.count().then(function (pagination) {
if (pagination > 0) {
for (var i = 0; i < pagination; i++) {
summaryPage.getPaginationsize.get(i).click();
}
} else {
console.log('Pagination not exists');
}
});

this.getPaginationsize = element.all(by.repeater('page in groupArray track by $index'));
this.getPaginationsize.count().then(function (pagination) {
if (pagination > 0) {
for (var i = 0; i < pagination; i++) {
summaryPage.getPaginationsize.get(i).click();
}
} else {
console.log('Pagination not exists');
}
you should change it to this as you are referring to the same module you are present in

Related

how to create an exception inside a flutter for loop

I need the items inside a for to have an action with the exception of the last one, which will have a different action
an example that DOESN'T WORK:
for (var i = 0; i < 10; i++) {
print('1 - 9');
if (i.last) {
print('last item');
}
}
You can put method in the condition part of the for loop. Here is such example:
void main() {
const limit = 10;
for(int i =0 ;
() {
if(i < limit && i < limit-1) {
doActionA(i);
return true;
}
else if(i < limit){
doActionB(i);
return true;
}
return false;
}()
; i++);
}
void doActionA(int i){
print('Not last $i');
}
void doActionB(int i) {
print('last $i');
}
output
Not last 0
Not last 1
Not last 2
Not last 3
Not last 4
Not last 5
Not last 6
Not last 7
Not last 8
last 9
Try this:
for (var i = 0; i < 10; i++) {
print('0 - 8');
if (i == 9) {
print('last item');
}
}
you can try this
for (var i = 0; i < 10; i++) {
print('1 - 9');
if (i==9) {
print('last item');
throw Exception("Your message");
}
}
This is also possible, you can just paste the snippet in DartPad and play with it
void main() {
try {
for (var i = 0; i < 10; i++) {
if (i == 3) {
print('item $i');
throw 'customError';
} else {
print('item $i');
}
}
} catch (e) {
if (e == 'customError') {
print('You caught your custom error \n $e');
} else {
print('You caught some other error');
}
}
}
Hope that will help

Listen to a new value of a bloc and generate a list of listened items

I have this StreamSubscription field called followSubscribtion. It listens if there is a new follower and then calls populateFollower to load follower profile.
followsSubscription =
getBloc(context).followsHandler.stream.listen((value) async {
if (value.status == Status.success) {
await populateFollows();
}
});
});
populateFollows() async{
if (getBloc(context).followsModel.length > 0) {
for (var i = 0; i < getBloc(context).followsModel.length; i++) {
getBloc(context).loadFollowsProfile(getBloc(context).followsModel[i].userId);
break;
}
}
}
This works fine, But I want each profile that will be loaded to be added to a list, How do I do that?
loadFollowsProfile method
loadFollowsProfile(int id , List<UserProfileModel> profileList) {
getFollowsProfileHandler.addNetworkTransformerStream(
Network.getInstance().getUserProfile(id), (_) {
userProfileModelBloc = UserProfileModel.fromJson(_);
profileList.add(userProfileModelBloc);
return userProfileModelBloc;
});
}
You can do this by setting up loadFollowsProfile() to return a UserProfileModel, adding that to a list in the for loop of populateFollows(), and then returning that list from populateFollows().
List<ProfileObject> populateFollows() async{
List<ProfileObject> profileList = [];
if (getBloc(context).followsModel.length > 0) {
for (var i = 0; i < getBloc(context).followsModel.length; i++){
profileList.add(getBloc(context).loadFollowsProfile(
getBloc(context).followsModel[i].userId
));
break;
}
}
return profileList;
}
followsSubscription =
getBloc(context).followsHandler.stream.listen((value) async {
if (value.status == Status.success) {
profileList = await populateFollows();
}
});
});

XMLHTTPRequest error but only when added to main project

so I have this code:
import 'dart:convert';
import 'package:http/http.dart' as http;
List getMenuDay(String day, List canteenMenu) {
if (day == "tuesday") {
return canteenMenu[0];
}
else if (day == "wednesday") {
return canteenMenu[1];
}
else if (day == "thursday") {
return canteenMenu[2];
}
else if (day == "friday") {
return canteenMenu[3];
}
else if (day == "saturday") {
return canteenMenu[4];
}
else if (day == "sunday") {
return canteenMenu[5];
}
else {
return [];
}
}
String getDayPlate(String day, String plate, List canteenMenu) {
List dayMenu = getMenuDay(day, canteenMenu);
if (plate == "sopa") {
return dayMenu[0];
}
else if (plate == "carne") {
return dayMenu[1];
}
else if (plate == "peixe") {
return dayMenu[2];
}
else if (plate == "dieta") {
return dayMenu[3];
}
else if (plate == "vegetariano") {
return dayMenu[4];
}
return "";
}
void main() async {
List list = [];
List helper = [];
const canteenUrl = 'https://sigarra.up.pt/feup/pt/mob_eme_geral.cantinas';
var response = await http.get(Uri.parse(canteenUrl));
if (response.statusCode == 200) {
var data = json.decode(response.body);
for (int i = 0; i < 4; i++) { // loop through different days
for (int j = 0; j < 5; j++) { // loop through different types of food
var parkInfo = data[3]["ementas"][i]["pratos"][j]["descricao"];
helper.add(parkInfo);
//print(parkInfo);
}
list.add(helper);
helper = [];
//print("--------------");
}
/*
for (int i = 0; i < list.length; i++) {
print(list[i]);
}
*/
print(getDayPlate("thursday", "carne", list));
} else {
throw Exception('Failed to read $canteenUrl');
}
}
and when I just create a new project, type it into the main.dart file and run it, it works fine. But when I add it to make whole project, including other files (making the necessary changed like changing the name of the function, etc), it gives me the XMLHTTPRequest error. What could be causing that? The way I'm calling it withing the main project is as follows:
ElevatedButton(
style: style,
onPressed: () {
CanteenInfo canteen = CanteenInfo("tuesday","sopa");
print(canteen.getDayPlate());
},
child: const Text('ShowLen (WIP)'),
Thanks for any help you could give!
Edit 1: I do get a warning when running just the code,
lib/main.dart: Warning: Interpreting this as package URI, 'package:new_test/main.dart'.

How to get specific Attributes of Object in GET request (with REST client)?

Guys i have a backend with a method that returns a finalList, which I wanted to test in my plugin "Advanced REST client", that can call different Methods combined with a request URL.
The method:
#GetMapping("/vokabelListe")
#ResponseStatus(HttpStatus.OK)
public Vokabel[] getVokabelListe() {
for (int i = 0; i < sehrWahrscheinlich.length; i++) {
if (finalList.length < 10) {
finalList[i].setVokabelENG(sehrWahrscheinlich[i].getVokabelENG());
finalList[i].setVokabelDE(sehrWahrscheinlich[i].getVokabelDE());
}
}
for (int i = 0; i < wahrscheinlich.length; i++) {
if (finalList.length < 13) {
finalList[i].setVokabelENG(sehrWahrscheinlich[i].getVokabelENG());
finalList[i].setVokabelDE(sehrWahrscheinlich[i].getVokabelDE());
}
}
for (int i = 0; i < nichtWahrscheinlich.length; i++) {
if (finalList.length < 15) {
finalList[i].setVokabelENG(sehrWahrscheinlich[i].getVokabelENG());
finalList[i].setVokabelDE(sehrWahrscheinlich[i].getVokabelDE());
}
}
while (finalList.length < 15) {
for (int i = 0; i < sehrWahrscheinlich.length; i++) {
finalList[i].setVokabelENG(sehrWahrscheinlich[i].getVokabelENG());
finalList[i].setVokabelDE(sehrWahrscheinlich[i].getVokabelDE());
}
for (int i = 0; i < wahrscheinlich.length; i++) {
finalList[i].setVokabelENG(sehrWahrscheinlich[i].getVokabelENG());
finalList[i].setVokabelDE(sehrWahrscheinlich[i].getVokabelDE());
}
for (int i = 0; i < nichtWahrscheinlich.length; i++) {
finalList[i].setVokabelENG(sehrWahrscheinlich[i].getVokabelENG());
finalList[i].setVokabelDE(sehrWahrscheinlich[i].getVokabelDE());
}
}
return finalList;
}
I just tested it, but it returns null for all indexes. I have to go through all indexes and get each VokabelDE, but i dont know how..

Need to update the Date format on my Google Mail Script

I'm creating a Gmail script that includes 5 variables, one of which is a due date. I just want it to populate as MM/DD/YYYY, however, it is currently populating as Thu Sep 13 2018 00:00:00 GMT-0400 (EDT).
Is there a way I can do that? I've pasted my code below for your reference. Any assistance is much appreciated.
function getRowsData(sheet, range, columnHeadersRowIndex) {
columnHeadersRowIndex = columnHeadersRowIndex || range.getRowIndex() - 1;
var numColumns = range.getEndColumn() - range.getColumn() + 1;
var headersRange = sheet.getRange(columnHeadersRowIndex, range.getColumn(), 1, numColumns);
var headers = headersRange.getValues()[0];
return getObjects(range.getValues(), normalizeHeaders(headers));
}
function getObjects(data, keys) {
var objects = [];
for (var i = 0; i < data.length; ++i) {
var object = {};
var hasData = false;
for (var j = 0; j < data[i].length; ++j) {
var cellData = data[i][j];
if (isCellEmpty(cellData)) {
continue;
}
object[keys[j]] = cellData;
hasData = true;
}
if (hasData) {
objects.push(object);
}
}
return objects;
}
function normalizeHeaders(headers) {
var keys = [];
for (var i = 0; i < headers.length; ++i) {
var key = normalizeHeader(headers[i]);
if (key.length > 0) {
keys.push(key);
}
}
return keys;
}
function normalizeHeader(header) {
var key = "";
var upperCase = false;
for (var i = 0; i < header.length; ++i) {
var letter = header[i];
if (letter == " " && key.length > 0) {
upperCase = true;
continue;
}
if (!isAlnum(letter)) {
continue;
}
if (key.length == 0 && isDigit(letter)) {
continue;
}
if (upperCase) {
upperCase = false;
key += letter.toUpperCase();
} else {
key += letter.toLowerCase();
}
}
return key;
}
function isCellEmpty(cellData) {
return typeof(cellData) == "string" && cellData == "";
}
function isAlnum(char) {
return char >= 'A' && char <= 'Z' ||
char >= 'a' && char <= 'z' ||
isDigit(char);
}
function isDigit(char) {
return char >= '0' && char <= '9';