简体   繁体   中英

Eclipse java appium test debug

I need to debug selenium/appium tests in eclipse that are written in Java. The script is running through eclipse and I can see it in the device but I hit some error so I wanted to debug. In eclipse I opened the debug perspective and setup break points in the script. Then I am running the test from Run --> Debug As --> TestNG Test , keeping everything else same.

But the code is not stopping at breakpoints. It is behaving like running the script normally (without debug). How do run so the code stop at breakpoints and then we step into?

Not sure if this is of help,but, This is how I am initiating the driver

public  AndroidDriver InitiateDriver() throws MalformedURLException {
          nodeURL= "http://localhost:4723/wd/hub" ;
          DesiredCapabilities capability =  DesiredCapabilities.android();
          capability.setCapability("BROWSER_NAME", "Android");
          capability.setCapability("VERSION", "7.0");
          capability.setCapability("platformName", "Android");
          capability.setCapability("appPackage", "com.accuweather.android");
          capability.setCapability("appActivity", "com.accuweather.app.SplashScreen");
          capability.setCapability("deviceName", "ec8d4453");

          AppDriver = new AndroidDriver(new URL(nodeURL), capability);
          return AppDriver;

      }

在Eclipse菜单栏中,转到“运行”菜单,并确保未选中“ Skip All Breakpoints ”( 跳过所有断点 )选项(如果已选择,则取消选择该选项)。

In trying to search for an answer to my question , I came across Appium Java REPL , which can be used for real time debugging of appium java tests.

Though its not with eclipse, but it solve the purpose here, which is to look for a solution for debugging java appium test.

We can utilize Appium Java REPL inbuilt driver and commands to start a new session and to find elements.

And we can also start a custom session (which is what I was looking for) so we can interact with elements like press a button using TouchAction class (shown below).

Make sure your android phone is connected and adb devices can list your device and appium server is up and running.

Just download the jar file and navigate to folder and run

java -jar appium-repl-0.2.0-BETA1.jar

then do

import static com.mobilebox.repl.Appium.*;

and then create custom session like this

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

import io.appium.java_client.*;

import io.appium.java_client.android.AndroidDriver;

import org.openqa.selenium.WebElement;



DesiredCapabilities capability =  DesiredCapabilities.android();

      capability.setCapability("BROWSER_NAME", "Android");

      capability.setCapability("VERSION", "7.0");

      capability.setCapability("platformName", "Android");

      capability.setCapability("appPackage", "your.app.package");

          capability.setCapability("appActivity", "your.app.activity");


          capability.setCapability("deviceName", "ec8d4453");

nodeURL= "http://localhost:4723/wd/hub" ;

driver = new AndroidDriver(new URL(nodeURL), capability);

TouchAction  touchAction = new TouchAction(driver);

WebElement allow= driver.findElementByAndroidUIAutomator(

"new UiSelector().className(\"android.widget.Button\").text(\"ALLOW\")"

);

touchAction.press(allow).release().perform().press(allow).release().perform();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM