Multiple Conditions in one expect - protractor

I want to Verify text of AssignedAllUsers List can contains test1 or test2 but it should not contain test3
I am using following but not sure what is the problem with the code I am getting following error : AllAssignee.toContain is not a function
this.IncList = element.all(by.repeater("incident in $ctrl.allIncidents"));
this.AssignedAllUsers = this.IncList.all(by.css('[aria-label="Change assignee to "]'));
AssignedAllUsers.getText().then(function(AllAssignee){
console.log("AllAssignee = "+AllAssignee);
expect((AllAssignee.toContain(Logindata.Username0)) || (AllAssignee.toContain(Logindata.Username1)) && (AllAssignee.not.toContain(Logindata.Username2)));
});

Your error is a syntax issue. toContain belongs outside the value being tested, in other words outside of the first set of parentheses following your expect statement.
You have this:
expect((AllAssignee.toContain(Logindata.Username0)). You also have an extra set of parentheses, though I don't think that really matters.
You need to close the AllAssignee call, it should be: expect(AllAssignee).toContain(Logindata.Username0)
To answer your other question, there's no need to do it in one expect statement really. Since the list should never contain test3, thats your first assertion:
expect(AllAssignee).not.toContain(test3);
As for your other expected values, if you do not know which one will be present, just create an array and put both possible values inside of that. Then you can assert against the array to contain either test1 or test2:
var myArray = ['test1', 'test2'];
expect(myArray).toContain(AllAssignee);
Also see this related question about expecting items items in an array

Able to fix the problem with the code:
expect(AllAssignee).toContain('test1' || 'test2');

Related

Incorrect syntax when attempting to use two values in order to create a parameter in SSRS

I'm attempting to create a parameter for when jodrtg.fdescnum <> inmastx.fbin1. I want to be able to use this in a dropdown list selection for my report. I have tried a number of combinations but keep getting syntax errors near the <or =.I'd be appreciative if anyone can point me in the right direction. I've never tried using two fields to create a single parameter before.
This what I've been attempting to get as my final result.
jodrtg.fdescnum <> inmastx.fbin1 = #MoldPress
I learned that you can only use one operator at a time but they can be combined using bool logic.
WHERE (jodrtg.fdescnum <> inmastx.fbin1
OR #ParameterName = 'Unfiltered')
AND (jodrtg.fdescnum <> inmastx.fbin1) OR #MoldPress = 0

Function runs twice in console (python3, eclipse)

Hi! Could you please explain why the function runs twice in console?
def changeList(myList1):
myList2 = myList1.append(4)
print(myList2)
return
myList1 = [1,2,3]
changeList(myList1)
print (myList1)
The result in console:
None
[1, 2, 3, 4]
Does it mean function runs twice as "None" appears in the console?
tl;dr - the function is only running once -- there are two print statements producing output
The function is not running twice: indeed, it is only being run once. The output in the console is instead coming from the two calls to print() contained within your program: one inside the function changeList() and one outside the function (print(myList1)).
None is being printed to the console because the return statement within the function changeList() isn't returning anything - there is no value to return:
If an expression list is present, it is evaluated, else None is
substituted.
[Taken from the Python 3.6 Documentation]
Seeing as how the return statement isn't doing anything, you can safely remove it - the function will still end anyway.
Hope that helps you out!
The function is running only once. You are appending one item to list and tried to store in other list by just assigning list with one more item appending which returns None and assigns to myList2. So, the code is wrong because append() function return's None.
I think you wan't to do like this so, here is the correct code:
comment if is it solved your problem or not.
def changeList(myList1):
myList2=[]
myList2.extend(myList1)
myList2.append(4)
print(myList2)
return
myList1 = [1,2,3]
changeList(myList1)
print (myList1)
Because in the function definition of changeList, there is a print statement, and then another print statement after calling changeList. The function is only running once actually, but you simply have two separate print statements.

JQuery Wildcard for using atttributes in selectors

I've research this topic extensibly and I'm asking as a last resort before assuming that there is no wildcard for what I want to do.
I need to pull up all the text input elements from the document and add it to an array. However, I only want to add the input elements that have an id.
I know you can use the \S* wildcard when using an id selector such as $(#\S*), however I can't use this because I need to filter the results by text type only as well, so I searching by attribute.
I currently have this:
values_inputs = $("input[type='text'][id^='a']");
This works how I want it to but it brings back only the text input elements that start with an 'a'. I want to get all the text input elements with an 'id' of anything.
I can't use:
values_inputs = $("input[type='text'][id^='']"); //or
values_inputs = $("input[type='text'][id^='*']"); //or
values_inputs = $("input[type='text'][id^='\\S*']"); //or
values_inputs = $("input[type='text'][id^=\\S*]");
//I either get no values returned or a syntax error for these
I guess I'm just looking for the equivalent of * in SQL for JQuery attribute selectors.
Is there no such thing, or am I just approaching this problem the wrong way?
Actually, it's quite simple:
var values_inputs = $("input[type=text][id]");
Your logic is a bit ambiguous. I believe you don't want elements with any id, but rather elements where id does not equal an empty string. Use this.
values_inputs = $("input[type='text']")
.filter(function() {
return this.id != '';
});
Try changing your selector to:
$("input[type='text'][id]")
I figured out another way to use wild cards very simply. This helped me a lot so I thought I'd share it.
You can use attribute wildcards in the selectors in the following way to emulate the use of '*'. Let's say you have dynamically generated form in which elements are created with the same naming convention except for dynamically changing digits representing the index:
id='part_x_name' //where x represents a digit
If you want to retrieve only the text input ones that have certain parts of the id name and element type you can do the following:
var inputs = $("input[type='text'][id^='part_'][id$='_name']");
and voila, it will retrieve all the text input elements that have "part_" in the beginning of the id string and "_name" at the end of the string. If you have something like
id='part_x_name_y' // again x and y representing digits
you could do:
var inputs = $("input[type='text'][id^='part_'][id*='_name_']"); //the *= operator means that it will retrieve this part of the string from anywhere where it appears in the string.
Depending on what the names of other id's are it may start to get a little trickier if other element id's have similar naming conventions in your document. You may have to get a little more creative in specifying your wildcards. In most common cases this will be enough to get what you need.

MATLAB: Referencing an element in a structure

I am trying to reference an element buried within a structure that I did not create (hence I don't know the exact way in which it was built).
Having loaded the structure, if I type:
dataFile.RECORDINGS.eye
I receive the following output:
ans =
2
ans =
2
Both of those variables will always be the same, but they could be at any time 1, 2 or 3. What I'd like to do is check with a switch statement which looks like this:
switch dataFile.RECORDINGS.eye
case {1, 2}
% action A
case 3
% action B
end
Of course, the above throws up an error because 'case' cannot check whether dataFile.RECORDINGS.eye contains a given value since there are two elements stored under that address. So, my question is: how do I reference just one of the elements? I thought it would be as simple as replacing the first line with:
switch dataFile.RECORDINGS.eye(1)
...But, this gives the error:
??? Field reference for multiple structure elements that is followed by more reference blocks is an error.
Similarly, I can't access the element like this:
switch dataFile.RECORDINGS.eye.1
...As I get the following error:
??? Dot name reference on non-scalar structure.
If the values are really always the same, you can try the following to get a scalar that can be used in the switch command:
unique([dataFile.RECORDINGS.eye])
By the way, did you try to index RECORDINGS, i.e.,
dataFile.RECORDINGS(1).eye
dataFile.RECORDINGS(2).eye
Perhaps instead of eye having multiple elements, you have multiple elements of RECORDINGS that each have a single value of eye? You might want dataFile.RECORDINGS(1).eye or dataFile.RECORDINGS(2).eye.

array_reverse() expects parameter 1 to be array, string given in

I am grabbing a .txt file and trying to reverse it, but I get this error when I try to, I don't understand it. Help please?
array_reverse() expects parameter 1 to
be array, string given in ......
Here is the code:
$dirCont = file_get_contents($dir, NULL, NULL, $sPoint, 10240000);
$invertedLines = array_reverse($dirCont);
echo $invertedLines;
A string is not an array? Even if it were (as in C strings) it would not work as you expected. You'll need to split the file on line breaks (if you're trying to reverse to get the end of the file first).
$invertedLines = array_reverse(preg_split("/\n/", $dirCont));
I think you need to pass the value on an array.
array_reverse(array($dircont));
This is working fine for me.