Code to click a radio button does not work the second time in my Protractor script - protractor

I am calling a function twice to execute a piece of code in my protractor script. A snapshot of the code of my function that is failing when called the second time is below. sessionNo is an argument passed to this function. It could be either 0 or 1. Depending on the value of this argument, either the radio button with index 0 will be selected or the radio button with index 1 will be selected.
function sessionBegin(sessionNo)
{
element.all(by.repeater('type in types')).all(by.css ("input[type='radio']")).isPresent(). then(function()
{
var sessionType = element.all(by.repeater('type in types')).all(by.css ("input[type='radio']")).get(sessionNo);
sessionType.click();
});
}
This code works great when this function is called for the first time. But when it is called the second time with a different value for sessionNo, it fails with "Failed: element not visible" error. I can't figure out why is the above code unable to locate the same element for the second time as it did for the first time with the exact same code.

It depends on your application code, may be your element becomes invisible between it's found and click action, or it's not visible yet. For the first case you should investigate what happens in application side, for second case (if it's not visible yet), you can wait until it became visible, for example: browser.wait(EC.visibilityOf(element), 5000, Element not visible: ${element.locator()});
it will wait for for element 5 seconds.

Related

How to not lose the updated variable in flutter?

Situation
I have a variable called number = 0 in my stateful widget in the second screen. Now, when a plus button is pressed it increases by 1 every time. Now when I go to first screen and come back to the second screen the variable again starts from 0 which I don't want.
Needed
When came back to second screen from first screen. I should have the updated variable.
How can I do that?
Try to create a static variable instead of a normal variable.
You can also try initializing the static variable in the first screen and pass it as an argument for better control.
But if you want the variable to be same even after reopening the app, you will have to save it to internal memory.
Hope it works!

Unexpected value in the text box by setText() method, even though expected value by getText() method print in console

I am a newbie and currently working on a project to build a Netflix-like desktop app on NetBeans. Users can select movies from a list to watch. I have two basic classes one to get, and the other one to set.
ONE TO GET:
OTHER ONE TO SET:
When a user clicks on jButton2('named Izle' on picture), the name of the film and the 'episode no.' passes to the filmIzleniyor class constructor, and then the film starts.
jButton2 SCREEN:
There are two text field on that frame, one shows the name, other shows the 'episode no.'. The program objects have an id attribute, and 1-50 of id's are cinema movies, the others (greater than 50) are TV series. Cinema movies 'episode no.' is 1. If the user selects a TV series, he must enter the 'episode no.' in the box.
filmIzleniyor SCREEN:
The problem is that if user selects a cinema movie (so there's no need to enter the episode no.) everything is OK, but if he selects a TV series then both text boxes on the frame show the first entry all the time. I mean in every attempt after the first attempt both text boxes repeat the first.
As you can see on pictures, I have tried some controls to detect, but nothing.
Print the value taken by getText method in the console shows the true value, but wrong text is written on the frame.
I found a solution that way:
I call the filmIzleniyor(int x, String y) constructor by using new keyword in another button's actionPerformed method, it's the first time to call that constructor in the program. The second time to call, i use the new keyword again then it creates another instance, so that the contents of the text components are loading two times. İt shows the first content in the screen, i dont know why?.

In what circumstances would I need to use Protractor ExpectedConditions to wait for an element

I'm new to working with Protractor and I was wondering in what circumstances would you need to use ExpectedConditions (example below) when using Protractor. I thought that Protractor automatically determine when an AngularJS page is fully loaded.
let EC = ExpectedConditions;
let condition = EC.presenceOf(element(by.id("something")));
browser.wait(condition, 10000);
Thanks, Eric
From my experience working with Protractor, the use of ExpectedConditions depends on the behavior of the page you are automating. It's mostly used due to failing if the condition doesn't comply in the specified time.
These conditions will also return a promise that you can handle to your liking.
I'll give you a few scenarios so you can understand where to use them.
alertIsPresent(): This condition will wait till an alert appears.
e.g.: After clicking a button, there will be an alert appearance; however, there's an API call which makes the pop-up take longer and also a small animation, so we want to wait a few seconds and no more than that.
// will click on a button
element(by.id('button')).click();
// will wait for the condition
let EC = ExpectedConditions;
browser.wait(EC.alertIsPresent(), 5000);
The following code will wait for 5 seconds after clicking the button, to see if the alert is present, else it will throw an error.
invisibilityOf(): This condition will wait till the specified element is not being displayed.
e.g.: There's a loader that appears for every single action that is triggered in the page. For this we want to wait till this loader disappears so we can continue with the automation process. By business requirements, this loader shouldn't take longer than 10 seconds.
This loader locks the whole page, so other elements are not interactable while it is up.
// trigger random action on page so loader appears
element(by.id('button2')).click();
// will wait for the condition
let EC = ExpectedConditions;
browser.wait(EC.invisibilityOf(element(by.id('loader'))), 10000);
After clicking a button, we will give a 10 seconds grace for the loader to disappear, else the condition will throw an error.
elementToBeClickable(): This condition will wait till the specified element can be clicked.
e.g.: The button to the login form is disabled by default, so it can't be clicked unless we complete the username and password textfields. The button being enabled after filling the textfields has a fast animation, either way we want to give it 1 second to complete and check if we are able to click it.
// complete both textfields required for the button to be enabled
element(by.id('username')).sendKeys('User1234');
element(by.id('password')).sendKeys('Protractor');
// will wait for the condition and then will click the button
let EC = ExpectedConditions;
browser.wait(EC.elementToBeClickable(element(by.id('loginButton'))), 1000);
element(by.id('loginButton')).click();
After completing both textfields, the condition will wait for 1 second for the element to be clickable, if it is, it will procede with the next line and click it. On the other hand, if it doesn't, an error will be thrown.
presenceOf(): In this case, the condition will check if the element is present in the DOM (Document Object Model) but it won't check if the element is visible or not.
e.g.: On a page with a radio button group containing 3 flavors: chocolate, vanilla and strawberry. Depending on which you choose, you will be shown different questions. Developers mentioned that the questions are in the page at all moments, but are hidden due to which radio button is selected at the moment. In this situation, we just want to check that all questions exist in the DOM, whether or not they will be shown by a radio button being selected.
// check all questions directly, without selecting any radio buttons
let EC = ExpectedConditions;
browser.wait(EC.presenceOf(element(by.id('question-1'))), 1000);
browser.wait(EC.presenceOf(element(by.id('question-2'))), 1000);
browser.wait(EC.presenceOf(element(by.id('question-3'))), 1000);
The time is pretty irrelevant here; nonetheless, using this conditions we will be able to check that the questions, even though hidden, exist in the DOM. If one is missing, an error will cut the test immediately.
These were a few examples I've had to deal with in the past. The use of the conditions is situational and mostly they are useful when you want to use the existing conditions since they save you the time of building them yourself.
PD: More information can be found in the Protractor API.

setValue() simultaneously creating and deleting value

We currently have a button that when pressed the first time adds a node as follows /Users/UID/Interests/childByAutoID/"value" and when pressed again deletes the value at the node. The first time the button is clicked the value is added to the node and the value is deleted upon the second click however the third click results in a simultaneous creation and deletion of the value in the database. I cannot seem to understand if this is an issue on my end or with firebase. I have referenced my code below:
if(clickedArr[indexPath.row] == false){
cell.interestsImage.image = selImageArr[indexPath.row]
ref.child("Users").child(Auth.auth().currentUser!.uid).child("Interests").childByAutoId().setValue(titleArr[indexPath.row])
clickedArr[indexPath.row] = true
}
else{
ref.child("Users").child(Auth.auth().currentUser!.uid).child("Interests").observe(.childAdded, with: { (snapshot) in
if(snapshot.value as? String == self.titleArr[indexPath.row]){
self.ref.child("Users").child(Auth.auth().currentUser!.uid).child("Interests").child(snapshot.key).removeValue()
}
})
The first thing you have to fix is you implement the listener for any child added to the node in interest when the button is clicked the second time. what the listener does is when it is added, it deletes it. the listener doesn't go away unless you remove them like notification observers.
if your node only contains one value at a time, you can just fix it by changing child added to just value.
When you click the node the first time, you toggle clickedArr[indexPath.row] to true. But when you click it the second time, you don't toggle it to false. You need to do that.

SilverLight 4 DataGrid & MVVM: Using SelectionChanged trigger to check checkbox, but NotifyPropertyChanged causes crash

I have a DataGridCheckBoxColumn in my DataGrid which is to indicate the rows the user has selected. I want the checkboxes to be checked/unchecked with a single click. Making the column editable (i.e. IsReadOnly="False") means the user has to click twice (first click just selects the row, 2nd click changes the checkbox), so I decided to set/clear the property the column is bound to in the view model code in response to the SelectionChanged trigger firing.
Setting/clearing the property works fine, however as soon as I call NotifyPropertyChanged("name of collection the grid is bound to") to get the view to show the change, this causes the SelectionChanged trigger to fire again. This loops about 10 times until an exception is thrown.
If I remove the call to NotifyPropertyChanged, the SelectionChanged trigger fires once, but of course I don't see any change in the UI. The collection is a PagedCollectionView if this makes any difference.
How can I get this to work? Note - I am using MVVM pattern, so everything is done with bindings to View Model (no code behind).
Thanks
Sounds like you have a infinite loop by design.
but try using the selectionchanging instead of selectionchanged,
or put a isloading flag in your viewmodel and dont call the inotify if the isloading is true
I found a very simple solution that doesn't involve triggers or code behind. See: Silverlight single-click checkbox DataGrid columns
It seems to work by using a column template, but only providing the CellEditingTemplate and no CellTemplate.