Mahesh
Mahesh

Reputation: 129

Appium local testing

I would like to run local server tests on real devices using appium. Are there any existing capabilities which i could use to do so ? I basicall have a server running on a port on my local machine but would like to test it on a real device. For example i want to test http://locahost:3000 on a real device. how can this port be avaialble on the real mobile device? I know Browser/Stack or Sauce labs implement this using their own local binaries. Can this be done with appium ?

Note: I have my grid setup ready with real devices configured and i can run other tests normally.

EDIT: Just to make it clear and to avoid irrelevant answers. I am looking for something like network sharing from the machine where the tests are invoked to run on real devices. i want to to test a server which is hosted locally and not avilable on the internet.

Upvotes: 1

Views: 2104

Answers (2)

Muzzamil
Muzzamil

Reputation: 2881

Please check below link to apply proxy settings in Appium.

https://www.npmjs.com/package/appium-proxy#setup-a-basic-appium-proxy

Upvotes: 0

Suban Dhyako
Suban Dhyako

Reputation: 2526

In order to test on real device, your device must be connected to your computer. To run the test on multiple devices, multiple instance of appium server must be run. You must use device udid in DesiredCapabilities to run the test on the specific device.

To run the appium server in port 3000 you must run the following command in terminal:

appium -a 127.0.0.1 -p 3000 --session-override

Appium server must be installed in your system in order to run above command.

Using port 3000 is not recommended as other program may be using the same port.

To run the app in real device you can define your AppiumDriver and DesiredCapabilities like following:

public class Test1(){
  public static AppiumDriver<MobileElement> driver;
  public static void main(String[] args){
    DesiredCapabilities caps=new DesiredCapabilities();
    caps.setCapability(MobileCapabilityType.UDID, "your device udid");
    caps.setCapability(MobileCapabilityType.DEVICE_NAME, "android device");
    caps.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
    caps.setCapability("appPackage", appPackage);
    caps.setCapability("appActivity", appActivity);
    caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
    try{
      driver == new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:3000/wd/hub"), caps);
    }catch(Exception e){
      e.printStackTrace();
    }
}

Upvotes: 1

Related Questions