Running and communicating Calabash android and calabash iOS together

試著忘記壹切 提交于 2019-12-13 18:46:47

问题


Does anyone ever tried running calabash-ios and calabash android together.

Suppose I have installed application A in android and application B on iOS and want to send some message from application A and validate that in application B.

Please let me know if anyone have done this and or any idea how to do this it will be really helpful.

Regards, Nishant Singh


回答1:


I would say this has nothing to do with calabash as the 2 processes need a way to synchronise data hence you may want to try something like this Is communication between two ruby processes possible/easy?




回答2:


This answer is from memory, so apologies if any of it is incorrect. If I can get hold of my old code I will recheck this and update if necessary.

NOTE: My experience is for doing this using real devices, so it may differ slightly for simulators.

For android you can manually configure multiple instances of the driver.

@android_app1 = Calabash::Android::Operations::Device.new(self, 'DEVICE_SERIAL1', 123, '/path/to/app', '/path/to/testserver', 456)
@android_app2 = Calabash::Android::Operations::Device.new(self, 'DEVICE_SERIAL2', 124, '/path/to/app', '/path/to/testserver', 457)

Once instantiated, you can run methods on a specific device by calling it directly

@android_app1.reinstall_apps
@android_app2.reinstall_apps

Or you can use a method to define which device is the default one that you want it to run on. Then any calabash commands will run on that device. This setting is only applicable for android and doesn't affect iOS devices in any way.

Calabash::Android::Operations.set_default_device(@android_app2)
query("* text:'thing'") # Will be run on @android_app2
Calabash::Android::Operations.set_default_device(@android_app1)
query("* text:'some_other_thing'") # Will be run on @android_app1

From what I remember for iOS, you can set up the iOS driver in the same way as you would for the case where you are only using one device that's iOS, i.e. setting environment variables. To use the iOS device you need to make sure there is a setting for one of the environment variables, I think it was DEVICE_ENDPOINT. If this environment variable is set with the iOS device's ip, then any commands from calabash will be sent to the iOS device. If it is set to an empty string then any calabash commands will be sent to the android device.

So assuming that you have the iOS environment variables all configured correctly, and that you have a constant IPHONE_IP which contains you iOS device IP.

# Start app on iOS device. Assuming you have set your env vars as per the docs.
@calabash_launcher = Calabash::Cucumber::Launcher.new
@calabash_launcher.relaunch
@calabash_launcher.calabash_notify(self)

ENV['DEVICE_ENDPOINT'] = '' # Clear this env var so that android is targeted

@android_app1 = Calabash::Android::Operations::Device.new(self, 'DEVICE_SERIAL1', 123, '/path/to/app', '/path/to/testserver', 456)
@android_app2 = Calabash::Android::Operations::Device.new(self, 'DEVICE_SERIAL2', 124, '/path/to/app', '/path/to/testserver', 457)

# Do some stuff declaring which device to act on each time.
@android_app1.reinstall_apps # Runs on @android_app1
@android_app2.reinstall_apps # Runs on @android_app2

# Do some stuff by defining which device you want to be used
Calabash::Android::Operations.set_default_device(@android_app2)
query("* text:'thing'") # Will be run on @android_app2
Calabash::Android::Operations.set_default_device(@android_app1)
query("* text:'some_other_thing'") # Will be run on @android_app1

# Now to use the iOS device
ENV['DEVICE_ENDPOINT'] = IPHONE_IP # Set so that calabash knows to use iOS device
query("* text:'thing'") # Will be run on iOS device

ENV['DEVICE_ENDPOINT'] = ''
query("* text:'thing'") # Will be run on @android_app1 as it is still set to be the default android device

I ended up making a class that dealt with this stuff for me, as it gets annoying having to add and remove the env var, and switch between devices. I also ended up moving away from the complicated cross platform multi device implementation in favour of using mocks. Hope this works for you!



来源:https://stackoverflow.com/questions/35130469/running-and-communicating-calabash-android-and-calabash-ios-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!