wix / Detox

Gray box end-to-end testing and automation framework for mobile apps
https://wix.github.io/Detox/
MIT License
11.16k stars 1.92k forks source link

Run on hardware iOS device #95

Open saikrishna321 opened 7 years ago

bvodola commented 5 years ago

@LeoNatan my company would greatly benefit from this feature. And I am interested in helping. I could dig into it and create a PR once I have something. Could you guide me or maybe give me some hints on this, so I could get started? Thanks!

LeoNatan commented 5 years ago

This comment mentions everything I've done in POC to get it to work on a real device, as well as challenges I've met or think will be difficult to tackle. Here is more info:

The general gist of how we inject Detox into apps on simulators is as follows:

  1. Take a user's .app and install it on simulator
  2. Launch app with DYLD_INSERT_LIBRARIES environment variable to ask the operating system to load the Detox dylib
  3. We pass launch arguments to the process to control how Detox functions.

We believe this is a good process that requires nothing from "Xcode-challenged" users and we would like to keep as much as possible of it. So, from a possible solution, we need the following requirements:

  1. Be able to install an app on a device
  2. Be able to inject an environment variable—only possible when running a process through debugserver
  3. Be able to pass launch arguments—only possible when running a process through debugserver

Other considerations: • On the simulator we are able to load the Detox dylib from any folder on the Mac machine—this is not possible on iOS obviously, so need to be able to somehow send the Detox dylib somewhere accessible within the app sandbox • In order for the iOS kernel to allow the loading of dylib, it has to be signed with the same codesign identity as the hosting app • Permissions will not be editable (no Apple~Simulator~DeviceUtils yet :stuck_out_tongue_winking_eye:)

I did a POC to check what is needed in general to run on device. With my own fork of ios-deploy I was able to install a test app on a device, set environment variables before launch and then launch the process with arguments. In my POC, I used a script that took the original .app, extracted the signing information, embedded the Detox dylib inside the bundle and resigned it. This obviously requires the certificate private key, which is not optimal for a testing cloud. So a research has to be done to see how to pass this dylib somehow without modifying the app bundle. Perhaps ios-deploy can do this and I didn't see. If this hurdle is solved, we are in a good shape to have a device driver for real devices.

rawqing commented 5 years ago

It seems that you have a practical solution, but it is troublesome. Could you first provide a manual configuration solution, let us study together, and then consider the adaptation of the cloud test platform? I can't wait to try! Your contribution is admirable!

lawrencelomax commented 5 years ago

@LeoNatan these are indeed similar constraints to what idb has to work with.

Essentially the constraints about going through a debugserver to get anything done w.r.t app launching on devices holds on iOS Devices.

On the simulator we are able to load the Detox dylib from any folder on the Mac machine—this is not possible on iOS obviously, so need to be able to somehow send the Detox dylib somewhere accessible within the app sandbox

If the detox lib is part of the App bundle, then you are able to dynamically link it, even using preloads like DYLD_INSERT_LIBRARIES, it's essentially a directive to dyld like any linker directive in the main app image.

The regular use-case here is splitting up an application into a smaller main executable that is loaded on launch and then other dylibs for features within an application. This is used to improve launch time so that that only the main dylib needs to be loaded when the app is launched and additional features can be linked only when they are needed.

LeoNatan commented 5 years ago

@lawrencelomax We decided to go that route to ease the setup and potential deployment issues of our users. They don't change their project and the system automagically adds the required Detox code in runtime.

Once we are able to sign applications with Detox for running on device (in order to add the Detox dylib inside the bundle), it will be trivial to modify the signed entitlements to allow debugger attach.

maxkomarychev commented 5 years ago

hey @LeoNatan I was wondering, how big are changes which you are trying to save users from in this

We decided to go that route to ease the setup and potential deployment issues of our users. They don't change their project and the system automagically adds the required Detox code in runtime.

scenario?

There's amazing xcodeproj project which lets you do pretty much anything you want with xcode project.

So is there another problem on they way if we can implement a solution which manipulates over user's project in the cloud w/o bothering a user to configure detox manually and then maintain parallel versions of the app (with and w/o detox libs).

update

user's project in the cloud w/o bothering a user to configure detox manually and then maintain parallel versions of the app

*or actually before uploading to the cloud

LeoNatan commented 5 years ago

@maxkomarychev Yes, I am familiar with that project, thank you. We used to use xcodeproj before settling to the current system. In some ways, it was terrible (not xcodeproj, but our previous solution). Detox would make a change in the user's project; since a lot of our users are ... "Xcode challenged" (to be as politically correct as I possibly can in this late hour), they would not understand the changes, and revert some or make changes of their own. We used to have problems with people complaining about changes. Changes done using xcodeproj were hard to change if we wanted to make a change in Detox. Big mess. We won't be going back to that system, sorry.

In your cloud proposed method, signing would still be an issue. We could sign it with an internal certificate, but that cannot guarantee a 100% functioning app (for example, is an app uses iOS extensions, using application groups and accessing files in the group container, etc.). Also, since Detox does not have a centralized backend, every user that would like to run Detox on a device would require them setting up this cloud on their own. I find it easier to just do everything locally (including signing with their own certificate).

pvinis commented 4 years ago

Is there any work happening on this one?

LeoNatan commented 4 years ago

No work, sorry. We are working on rewriting large portions of the project, which should in theory make running on hardware device easier.

pvinis commented 4 years ago

Is this happening in open source or is it more of an internal wix effort?

LeoNatan commented 4 years ago

Detox is an open source project, so the changes will be available once ready.

fjmorant commented 4 years ago

Hi,

How is this feature going? Do you have any updates?

Thanks

LeoNatan commented 4 years ago

This is not a priority for us. No updates right now.

fjmorant commented 4 years ago

But it is part of the roadmap

https://github.com/wix/Detox/blob/master/docs/More.Roadmap.md#ios-physical-device-support

is there any plan to make it available at some point?

Thx

rotemmiz commented 4 years ago

Referencing @LeoNatan's answer https://github.com/wix/Detox/issues/95#issuecomment-541563023

This is not a priority for us as we still see Simulators as a good enough tool for our testing. The Detox iOS rewrite will make this potentially easier to support, but we'll still need to put some effort into it as a separate task once the rewrite is done. Re the roadmap, you are right, but it needs a refresh.

LeoNatan commented 4 years ago

The roadmap document isn't really maintained. As part of the rewrite, we need to go over documents and remove some of the more esoteric ones which we don't actively maintain (such as the roadmap one).

fjmorant commented 4 years ago

Hi @rotemmiz and @LeoNatan ,

Thanks for your replies and for giving me a bit of the context with your current situation, I will keep an eye to the latest releases.

Kind Regards

LeoNatan commented 4 years ago

With the pending rewrite, some of the more peculiar deployment issues should be solved (no need for ios-deploy and ability to easily set an environment variable), but some issues will still remain, such as deploying the Detox dylib on device and signing it correctly so it can be loaded on device. Those aren’t particularly hard to solve but require thinking and perhaps additional requirements from the user. Once we finish the rewrite effort, we can revisit this topic.

TammyTorres commented 4 years ago

@LeoNatan Is not clear for me if till today is possible or not to run on real devices from documentation https://github.com/wix/Detox/blob/master/docs/APIRef.Configuration.md I'm not seeing how to do it

LeoNatan commented 4 years ago

Well, clearly it is not possible, as evident by the discussion here.

TammyTorres commented 4 years ago

thanks! just want to be sure . Is something that would be possible to provide soon? @LeoNatan

LeoNatan commented 4 years ago

Not currently planned, as stated many times before. We are working on overhauling Detox’ internals for iOS, which will make it easier.

iradkot commented 3 years ago

I see the discussion kind of repeat itself, but still, 7 months since last reply, are there any plans on supporting ios physical device in the near future?

LeoNatan commented 3 years ago

Not in the very near future, but we keep this thread open for a reason. We are moving the pieces slowly toward that goal.

andreialecu commented 3 years ago

@LeoNatan I was following #2198 and I just noticed it was merged and published as 18.0.0 but couldn't find any release notes yet.

Does it bring real device support? Can we now run on services like AWS Device Farm?

LeoNatan commented 3 years ago

No. Running on iOS hardware will take a lot more work.

LeoNatan commented 3 years ago

There is no need to ask about this every few months or after every release. The issue is open, and we haven't forgotten about it. Once the work has been done and we are ready to add this support, we will surely write about it here in the issue, as well as in the release notes. Thanks