Can I check the number of buttons in a screen in appium - java

I'm landing in a screen which has 10 or more buttons. I just want to check how many buttons are present in the screen when opened for the first time.

I have never personally tried this but there is a findElements(By) function which gives you back a list of elements. So I would assume you could just get the number of buttons by getting the size of the returned list.
That is driver.findElements(By.xpath("//<Button Type depending on OS>").size();
For example for xcode 8:
int numButtons = driver.findElements(By.xpath("//XCUITestButton")).size();
Note I am writing this response away from

In Android, if you do WebElements it will show you only those elements that are present on the visible screen. In your case if all the buttons are present on the visible screen then you can just call WebElements to find the count of buttons.
List<WebElement> buttons = driver.findElements(By.className(android.widget.Button));
System.out.println(list.size());
Otherwise you would have to scroll down on the screen and then keep on adding to your list to get the complete list of buttons.

Related

Android Studio varying number of buttons

How can I have a varying number of buttons with androidstudio? So lets say there is a list and for each (not null) element in this list a button is shown to a particular user. Other users might add or remove elements in this list, i.e. the number of buttons displayed needs to be able to change over time.
I just ask for a hint to an appropriate libary/approach/... to this (google doesnt give good results for this)... the rest i try to figure myself then.
Any help is apprechiated!

How to change item position of RecyclerView before the 0 element in my ArrayList

I have a RecyclerView with a cell row that have a favorite button. I was searching on SO and found a question with the same thing that I want to do here : implementing "add to favourite" mechanism in RecyclerView
the problem is that is not clear for me for now.
I dont want to have 2 recyclerViews and delegate the view to the other one because I will need to have 2 onCreateViewHolders and will be really unconfortable to work with, also bad coded.
What I need to do is like a row and then move it to the top with the title Favorite on it.
What comes to my mind is just delete the item im clicking and moving it to the 0 position of my ArrayList<Object> , but if I move that element to the 0 position it will overwrite my current element in the 0 position. Instead, I need to create a transparent row cell that says for example Favorites, and then below that cell (assuming is before 0 position in my array) start adding the favorites below it.
I will illustrate what I need to do.
This image is in the same RecyclerView without creating a new one above to show favorites. What I need to do is clicking one element, removing it and just replace it at the top of the RecyclerView but with a text on the top that says favorites, and after that each element that I add to the favorite list is just placed below the latest one there, so I was wondering what is the best way to accomplish this behaviour
This is what I need, pressing to like below, and then have my liked rows above, all in one place.
Thanks for any hint !

Efficient Algorithm - Comparing lists with Virtual Scrolling

I need to test an application through UI where there are two panels.
One being available items and the other is selected items
These panes can contain thousands of items
Each available item has a checkbox used to select it and then the add button will add it to the selected pane.
My problem is there is virtual scrolling implemented on the panels.
Meaning I can only ever access a maximum of 16 items at a time,
(I've tried scrolling down to the bottom - but still, css selectors only work for the items I can see on the screen)
My Question is what is the best way to test this in terms of moving items from one panel to the next?
Possible approaches:
1) Move available items over to the selected items list (16 at a time) and assert they 16 got moved correctly ?
2) Move items over one by one asserting as I go they moved ok
3) Save all available items to a list then add them all over and compared the selected items to the saved list.
Could threading be an option?
Arquillian, Drone and Graphene are used so tests are done with page objects using Java

Showing a counter dynamically for JList items highlighted

I have a program that I created for work. This program takes an uploaded file, reads it, and puts the data into a JList in the GUI. The GUI actually has two lists and the user is able to move items between the left and right list by highlighting them like usual with a JList and then hitting an arrow to move the items. The lists are multiple-interval selection.
One small addition I would like to add is some type of counter that shows the user how many items they have selected before they actually move them between lists. This would need to be dynamic so if the user holds control down and begins clicking the counter will continue to update the number of highlighted items.
As the lists are often quite large and a user might need to move an odd number of transactions between the lists (Think 300 transactions in left list and the user needs to move exactly 50) it would be beneficial to have this counter.
Can anyone think of how this could be done? I'm not sure how to add an action listener to just clicking on the items. Please also let me know if I need to elaborate any more.
Generally my question is can I create an action listener just for when a user clicks a item in a JList that updates a counter for the current selected indices? Also it would need to change when they no longer have selected an indice.
Register a ListSelectionListener with your JList.
The listener could simply query how many rows are selected and update the number in the panel to that. Perhaps use getSelectedValues().size().
http://docs.oracle.com/javase/8/docs/api/javax/swing/JList.html#addListSelectionListener-javax.swing.event.ListSelectionListener-

Change color of JButton when selected, & Set mask on JFormattedTextField?

I'm writing my 1st Java program (in Netbeans) and I'm lost. I have 2 questions at the moment, if anyone is kind enough to help me.
Here's what the program is supposed to do:
take 1 of 4 "status" options, plus a 5 digit number (both of these items are entered by a user via a touch-screen monitor) and then email this info to someone with the subject line of: "Item #[5 digit number from JFormattedTextField] is currently [1 of 4 possible status options].
Email command would command after user clicks "enter" button, and then user clicks "OK" on a pop-up which asks user to confirm message about to be emailed. As far as my 3rd question, it's about the e-mailing part, and I figured that would be a another thread after I get this button & text field stuff ironed out.
Here's a picture of the touch screen UI I have so far:
(can't post images as a rookie, go to krisbunda.com/gui.png for this image)
Question #1:
the 4 status options (4 JButtons) are wrapped inside of a JPanel. I want the most recent button to have been pushed in the "statusPanel" JPanel to change the background to blue and the button text to white.
Can I put a mouselistener on the button's parent JPanel to listen for click events on the children (the 4 status JButtons), and then whichever button was last clicked, it will turn blue w/ white text? Please point me in the right direction.
Question #2:
I have a JFormattedTextField named "display" that shows the numbers as they're clicked, which are appended from a StringBuffer named "current". I want the text field to only accept a total of 5 numbers.
When I tried putting a mask of "#####" on the field, it would only chime a warning beep when I pushed the number pad's buttons. Currently I've chosen "Category: number" and "Format: custom" and then typed "#####" in the "Format:" field. This allows me to click number buttons and see their text displayed, but it doesn't stop me from typing more than 5 characters.
I'm doing this through the "Properties> FormatterFactory" dialog box. A screen shot is shown below:
(go to krisbunda.com/text-formatterFactory.png to view this image)
And here's the code I have so far:
(my post was too long with this code, so go to: krisbunda.com/java-sampleCode.txt to view)
Thanks in advance for any help!
Your code looks fine, and you already have fields set up to hold references to all your buttons, so now you just need to write the code inside the status setting buttons and then make them call a subroutine with the new status. This subroutine should then reset all the buttons to their default color and then set the special selected color on the button that corresponds to the new or existing status.
Edit: adding code here in response to your comment...
Firstly, never use == with Strings. You MUST use equals() otherwise when you get two Strings that are identical, but are different objects, they will not be the same and your comparisons will fail.
There are much better ways of coding this up, including using enums etc. but this should work for you:
// Reset all the buttons
outsideNotReadyButton.setBackground(...);
loadedButton.setBackground(...);
outsideReadyButton.setBackground(...);
shippedButton.setBackground(...);
// Now set the one of the button's colors conditionally
String status = ...
if(status.equals("SHIPPED")) {shippedButton.setBackground(Color.BLUE);}
else if(status.equals("LOADED")) {loadedButton.setBackground(Color.BLUE);}
// ...and so on
An ActionListener is the more common approach to buttons, as discussed in How to Use Buttons, etc. A FocusListener, also used in this example, is one way to change a button's appearance in the way you describe.
An sscce showing just your JFormattedTextField problem will be more helpful. Several such examples may be found in the article How to Use Formatted Text Fields.

Categories