1

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.

Mahesh
  • 129
  • 1
  • 2
  • 19

2 Answers2

1

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();
    }
}
Suban Dhyako
  • 2,436
  • 4
  • 16
  • 38
  • irrelavant answer idon't want to run appium on 3000 port. i want to test a local server running 3000 on real device – Mahesh Feb 28 '19 at 11:10
  • what do you mean by local server running 3000 on real device? what are you trying to achieve? Do you want to run appium testing using tcp? – Suban Dhyako Feb 28 '19 at 11:27
  • ok. i will give you an example. if you can launch a selenium server on your local machine on port 4444, you can access it on your mahcine with address http://localhost:4444 and from any other external machine/mobile device with http://ipaddress:4444. But when you are running the same selenium server inside a docker container, you cannot access it from external machine/device. This is where i was looking for resource sharing. I basically want real devices to use a server which is running on gitlab ci test runner and run the tests. – Mahesh Feb 28 '19 at 12:26
0

Please check below link to apply proxy settings in Appium.

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

Muzzamil
  • 2,823
  • 2
  • 11
  • 23
  • 'appium-proxy' is a proxy for appium server that supports to keep the server alive for a long time. It is suitable for running test cases belong with one session id. ^^ not what i am looking for. – Mahesh Feb 28 '19 at 11:11