Appium cannot click on google Search button - appium-ios

I use Xcode 9.3, Appium desktop 1.6.2, i run safari on simulator
I try to enter to google page and i do a search (sendkey) but i cannot click on Search button
private IOSDriver driver;
#Before
public void setUp() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName", "iOS");
desiredCapabilities.setCapability("platformVersion", "11.3");
desiredCapabilities.setCapability("deviceName", "iPhone x");
desiredCapabilities.setCapability("browserName", "Safari");
// desiredCapabilities.setCapability("nativeWebTap", true);
desiredCapabilities.setCapability("udid", "39789C6E-6119-47CC-BD2D-883F491EE93B");
desiredCapabilities.setCapability("automationName", "XCUITest");
//desiredCapabilities.setCapability("app", "/Users/faroukrahem/Downloads/IntactInsuranceDebug.ipa");
//desiredCapabilities.setCapability("xcodeOrgId", "N2E34G93LZ");
//desiredCapabilities.setCapability("xcodeSigningId", "iPhone Developer");
URL remoteUrl = new URL("http://localhost:4723/wd/hub");
driver = new IOSDriver(remoteUrl, desiredCapabilities);
}
#Test
public void sampleTest() throws InterruptedException {
driver.get("http://www.google.com");
driver.findElement(By.name("q")).sendKeys("farouk rahem");
driver.findElement(By.name("btnG")).click();
Thread.sleep(10000);
}
#After
public void tearDown() {
driver.quit();
}
}

Better to use Accessibility Id instead of name or else you can ask your developers to provide unique accessibilityId for that element.

Related

System.NotSupportedException: Unable to activate instance of type MyProject.CancelListener from native handle

In my Xamarin Forms app, I am using native Android code for the platform. I want to show a AlertDialog.Builder and catch the event when the user taps outside of the dialog box with SetOnCancelListener. This is my code:
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.SetTitle("title");
adb.SetItems(myItems.Select(x => x.Name).ToArray(), (s, e) =>
{
// not important code
});
var cancelled = new CancelListener();
cancelled.Cancelled += (s, e) =>
{
// not important code
};
adb.SetCancelable(true);
adb.SetOnCancelListener(cancelled);
Dialog d = adb.Create();
d.Show();
My CancelListener class:
public class CancelListener : Java.Lang.Object, IDialogInterfaceOnCancelListener
{
public event EventHandler Cancelled;
public IntPtr Handle => IntPtr.Zero;
public CancelListener() : base()
{
}
public void Dispose()
{
Cancelled = null;
}
public void OnCancel(IDialogInterface dialog)
{
Cancelled?.Invoke(null, EventArgs.Empty);
}
}
When I tap outside of the dialog box I get the message:
System.NotSupportedException: Unable to activate instance of type
MyProject.CancelListener from native handle

JavaFX WebView not loading graph data from url (WebSocket?)

Using this code and the hardcoded url, the graph in the url doesn't load. I tried disabling my firewall and running it under JDK 9 with a pre-release build of Netbeans 9. No luck. A WebSocket test says that WebSocket is working fine (url commented out in the code). Any ideas what's wrong or what I should check? My guess is it has to do with WebSocket regardless of the test results. I'm using Netbeans 8.2 and jdk1.8.0_144.
//
// Code from https://stackoverflow.com/questions/42297864/javafx-webview-in-java-project
//
public class FXWebViewInSwing {
private JFXPanel jfxPanel;
public void createAndShowWindow() {
JFrame frame = new JFrame();
JButton quit = new JButton("Quit");
quit.addActionListener(event -> System.exit(0));
jfxPanel = new JFXPanel();
Platform.runLater(this::createJFXContent);
JPanel buttonPanel = new JPanel();
buttonPanel.add(quit);
frame.add(BorderLayout.CENTER, jfxPanel);
frame.add(BorderLayout.SOUTH, buttonPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1024, 576);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private void createJFXContent() {
WebView webView = new WebView();
webView.getEngine().load("https://www.tradingview.com/chart/bKsZf5LY/");
// webView.getEngine().load("https://websocket.org/echo.html");
Scene scene = new Scene(webView);
jfxPanel.setScene(scene);
}
public static void main(String[] args) {
FXWebViewInSwing swingApp = new FXWebViewInSwing();
SwingUtilities.invokeLater(swingApp::createAndShowWindow);
}
}

how to use progressbar when loading image in picasso?

I want onStart() method to load image from server using picasso and I want to show a progress bar until the photos are fully downloaded
Here is my code:
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Picasso.with(context).load(imageLoad)
.placeholder(R.id.progressBarDetails)
.error(R.drawable.friend_request).noFade().resize(200, 200)
.into(avatarImage, new Callback() {
#Override
public void onError() {
// TODO Auto-generated method stub
}
#Override
public void onSuccess() {
// TODO Auto-generated method stub
progressbar.setVisibility(View.GONE);
}
});
Picasso.with(this).load(imageLoad).into(target);
}
OnFinished a = new OnFinished() {
#Override
public void onSendFinished(IntentSender IntentSender, Intent intent,
int resultCode, String resultData, Bundle resultExtras) {
// TODO Auto-generated method stub
intent = new Intent(getApplicationContext(), Map.class);
}
};
private Target target = new Target() {
#Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
new Thread(new Runnable() {
#Override
public void run() {
File file = new File(Environment
.getExternalStorageDirectory().getPath()
+ "/actress_wallpaper.jpg");
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 75, ostream);
ostream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
I haven't tested your code but even if that works, the file actress_wallpaper.jpg isn't loaded in the ImageView. In the docs, it says
Objects implementing this class must have a working implementation of Object.equals(Object) and Object.hashCode() for proper storage internally.
Try this:
File file = new File(pathToFile);
Picasso.with(context)
.load(file)
.into(imageView, new Callback() {
#Override
public void onSuccess() {
progressbar.setVisibility(View.GONE);
}
});
be warned I haven't tested my code.
Update:
I have tried version 2.3.2 and 2.3.3, it seems like that there's an issue https://github.com/square/picasso/issues/539
It is an old question but may be this answer can help others as I also had issues in showing progress bar while loading image from server.
I am using Picasso 2.4.0. and I am using Picasso Target interface to load image in imageview. Here is the tested and working code:
First add the following lines:
ImageView ivPhoto = (ImageView) findViewById(R.id.iv_photo);
ProgressBar pbLoadingBar = (ProgressBar) findViewById(R.id.pb_loading_bar);
//get image url
String imageUrl = getImageUrl();
//ImageViewTarget is the implementation of Target interface.
//code for this ImageViewTarget is in the end
Target target = new ImageViewTarget(ivPhoto, pbLoadingBar);
Picasso.with(mContext)
.load(imageUrl)
.placeholder(R.drawable.place_holder)
.error(R.drawable.error_drawable)
.into(target);
Here is the implementation of Target interface used above
private static class ImageViewTarget implements Target {
private WeakReference<ImageView> mImageViewReference;
private WeakReference<ProgressBar> mProgressBarReference;
public ImageViewTarget(ImageView imageView, ProgressBar progressBar) {
this.mImageViewReference = new WeakReference<>(imageView);
this.mProgressBarReference = new WeakReference<>(progressBar);
}
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
//you can use this bitmap to load image in image view or save it in image file like the one in the above question.
ImageView imageView = mImageViewReference.get();
if (imageView != null) {
imageView.setImageBitmap(bitmap);
}
ProgressBar progressBar = mProgressBarReference.get();
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
ImageView imageView = mImageViewReference.get();
if (imageView != null) {
imageView.setImageDrawable(errorDrawable);
}
ProgressBar progressBar = mProgressBarReference.get();
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
ImageView imageView = mImageViewReference.get();
if (imageView != null) {
imageView.setImageDrawable(placeHolderDrawable);
}
ProgressBar progressBar = mProgressBarReference.get();
if (progressBar != null) {
progressBar.setVisibility(View.VISIBLE);
}
}
}
The above code works fine if used for loading image in activity. But if you want to load image in gridview/recyclerview or view pager etc. where same view holder is used, you might get an issue where onBitmapLoaded() is not called (as the view is recycled and Picasso only keeps a weak reference to the Target object). Here is a link to solve this problem.
change to this
Picasso.get()
.load(tImageUrl())
.into(holder.AnimImage, new Callback() {
#Override
public void onSuccess() {
holder.progressBar.setVisibility(View.GONE);
}
#Override
public void onError(Exception e) {
}
});

Retrieving mouse-clicks in Graphstream

Since I couldn't find any specific place to discuss this, I thought I'd post here...
I'm using graphstream 1.1 (http://graphstream-project.org/), a graph visualization library for java, to develop a data visualization tool. I'm needing to retrieve mouseclicks on nodes to display related data, but after following the library tutorial, it's still not clear for me how to do this. Does anyone that used this could help me out here with a more straightfoward answer? The tutorial I'm following is at:
http://graphstream-project.org/doc/Tutorials/Graph-Visualisation_1.0/#retrieving-mouse-clicks-on-the-viewer
public class Clicks implements ViewerListener {
protected boolean loop;
public static void main(String args[]) {
new Clicks();
}
public Clicks() {
// We do as usual to display a graph. This
// connect the graph outputs to the viewer.
// The viewer is a sink of the graph.
Graph graph = new SingleGraph("Clicks");
Viewer viewer = graph.display();
// The default action when closing the view is to quit
// the program.
viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.HIDE_ONLY);
// We connect back the viewer to the graph,
// the graph becomes a sink for the viewer.
// We also install us as a viewer listener to
// intercept the graphic events.
ViewerPipe fromViewer = viewer.newViewerPipe();
fromViewer.addViewerListener(this);
fromViewer.addSink(graph);
// Then we need a loop to wait for events.
// In this loop we will need to call the
// pump() method to copy back events that have
// already occured in the viewer thread inside
// our thread.
while(loop) {
fromViewer.pump();
}
}
viewClosed(String id) {
loop = false;
}
buttonPushed(String id) {
System.out.println("Button pushed on node "+id);
}
buttonReleased(String id) {
System.out.println("Button released on node "+id);
}
}
Just got it solved! I sent an e-mail to their mailing group. The tutorial code on the website was lacking some information. Those three functions need to be public void, and other 'imports' must be added:
import org.graphstream.ui.swingViewer.Viewer;
import org.graphstream.ui.swingViewer.ViewerListener;
import org.graphstream.ui.swingViewer.ViewerPipe;
Here a simple code to show you how to add click event to the nodes of a given graph in graphstream library. This code show how you can change the node's background by clicking on it. The colors are choosen randomly:
public class TutoMouseClicked{
Graph graph;
public TutoMouseClicked(){
}
public void run(){
//Build a simple graph with one node
graph = new SingleGraph("TutoMouseClicked", false, true);
graph.setAttribute("ui.quality");
graph.setAttribute("ui.antialias");
Node n1 = graph.addNode("n1");
n1.setAttribute("ui.style", "size: 100px;");
Viewer viewer = graph.display();
viewer.getDefaultView().setMouseManager(new TutoMouseManage());
}
public static void main(String args[]) {
new TutoMouseClicked().run();
}
}
And the class TutoMouseManage that implements MouseManager interface:
public class TutoMouseManage implements MouseManager{
/**
* The view this manager operates upon.
*/
protected View view;
/**
* The graph to modify according to the view actions.
*/
protected GraphicGraph graph;
protected GraphicElement element;
#Override
public void init(GraphicGraph gg, View view) {
this.graph = gg;
this.view = view;
view.addMouseListener(this);
view.addMouseMotionListener(this);
}
#Override
public void release() {
view.removeMouseListener(this);
view.removeMouseMotionListener(this);
}
#Override
public void mouseClicked(MouseEvent me) {
element = view.findNodeOrSpriteAt(me.getX(), me.getY());
if(element != null){
Random r = new Random();
element.setAttribute("ui.style", "fill-color: rgb("+r.nextInt(256)+","+r.nextInt(256)+","+r.nextInt(256)+");");
}
}
#Override
public void mousePressed(MouseEvent me) {
}
#Override
public void mouseReleased(MouseEvent me) {
}
#Override
public void mouseEntered(MouseEvent me) {
}
#Override
public void mouseExited(MouseEvent me) {
}
#Override
public void mouseDragged(MouseEvent me) {
}
#Override
public void mouseMoved(MouseEvent me) {
}
}
you can adapt this code to get what you need, add any other mouse event you want: mouse released, mouse pressed, mouse dragged and all mouse events.

AspectJ capture button clicked

I want to know whether how to capture the button clicked with AspectJ and get its parameter (eg. button name). I think for having more generalized capturing with AspectJ, it shoudl be used MouseListener so it can capture other UI elements in general!
Example:
In a GUI example I have defined 2 buttons that take some actions
public JButton btn1 = new JButton("Test1");
public JButton btn2 = new JButton("Test2");
btn1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//take some actions
}
}
btn2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//take some actions
}
}
How to capture these buttons with AspectJ, and get their parameters (eg. name)?
It is possible. I have provided two examples. The first that prints out for every JButton that has an ActionListener. The other example only prints out if a specific buttons is clicked.
Prints the text for every JButton clicked with an ActionListener:
#Pointcut("execution(* *.actionPerformed(*)) && args(actionEvent)")
public void buttonPointcut(ActionEvent actionEvent) {}
#Before("buttonPointcut(actionEvent)")
public void beforeButtonPointcut(ActionEvent actionEvent) {
if (actionEvent.getSource() instanceof JButton) {
JButton clickedButton = (JButton) actionEvent.getSource();
System.out.println("Button name: " + clickedButton.getText());
}
}
Prints the text for a specific JButton:
public static JButton j1;
#Pointcut("execution(* *.actionPerformed(*)) && args(actionEvent) && if()")
public static boolean button1Pointcut(ActionEvent actionEvent) {
return (actionEvent.getSource() == j1);
}
#Before("button1Pointcut(actionEvent)")
public void beforeButton1Pointcut(ActionEvent actionEvent) {
// logic before the actionPerformed() method is executed for the j1 button..
}
UPDATED:
You can do this in many different ways. For example add your buttons to the aspect directly. But I prefere to use a enum object between (ButtonManager in this case), so the code does not know about the aspect. And since the ButtonManager is an enum object, it is easy for the aspect to retrieve values from it.
I just tested it with a Swing button class from Oracle and it works. In the Swing class:
b1 = new JButton("Disable middle button", leftButtonIcon);
ButtonManager.addJButton(b1);
AspectJ is extremely powerful when it comes to manipulating classes, but it can not weave advises into specific objects since objects is not created at the time of weaving. So you can only work with objects at runtime and that is why I have added the addJButton(..) method above. That enables the aspect to check the advised button against a list of registered buttons.
The ButtonManager class:
public enum ButtonManager {
;
private static Collection<JButton> buttonList = new LinkedList<JButton>();
public static void addJButton(JButton jButton) {
buttonList.add(jButton);
}
public static Collection<JButton> getButtonList() {
return buttonList;
}
}
Modified pointcut and advice to only print the name of the buttons registered in the ButtonManager:
#Pointcut("execution(* *.actionPerformed(*)) && args(actionEvent) && if()")
public static boolean buttonListPointcut(ActionEvent actionEvent) {
Collection<JButton> buttonList = ButtonManager.getButtonList();
JButton registeredButton = null;
for (JButton jButton : buttonList) {
if (actionEvent.getSource() == jButton) {
registeredButton = jButton;
}
}
return registeredButton != null;
}
#Before("buttonListPointcut(actionEvent)")
public void beforeButtonListPointcut(ActionEvent actionEvent) {
JButton clickedButton = (JButton) actionEvent.getSource();
System.out.println("Registered button name: " + clickedButton.getText());
}
UPDATED 2
Okay, I believe I understand what you want. You want to listen to mouse events. That is possible. The downside is that you have to register all your GUI components that you want to listen for clicks with a mouse listener. It is not enough to register the JPanel of the JFrame with a MouseListener. So if you only have registered an ActionListener for your buttons, you also have to add a mouse listener.
I have created a quick solution that works for me. It only shows that it works. I have not tried to make the solution generic with many different GUI objects. But that should be quite easy to refactor in when you have got the basics to work.
In the Swing class:
private class MouseListener extends MouseInputAdapter {
public void mouseClicked(MouseEvent e) {}
}
In the init method of the Swing class:
MouseListener myListener = new MouseListener();
btn1.addMouseListener(myListener);
btn2.addMouseListener(myListener);
In the Aspect class:
#Pointcut("execution(* *.mouseClicked(*)) && args(mouseEvent)")
public void mouseEventPointcut(MouseEvent mouseEvent) {}
#Before("mouseEventPointcut(mouseEvent)")
public void beforeMouseEventPointcut(MouseEvent mouseEvent) {
if (mouseEvent.getSource() instanceof JButton) {
JButton clickedButton = (JButton) mouseEvent.getSource();
System.out.println("aspectJ --> mouseClicked: " + clickedButton.getText());
}
}
This results in the following output in the console:
aspectJ --> mouseClicked: Test1
I hope it helps!

Resources