xdissent / karma-ios-launcher

Karma launcher for the Xcode iOS Simulator
http://xdissent.github.io/karma-ios-launcher
MIT License
14 stars 0 forks source link

Simulator launches, but Safari does not open and tests never run #2

Open lazd opened 10 years ago

lazd commented 10 years ago

Enabling debugging shows the following:

  iosctrl:simulator new +0ms
INFO [launcher]: Starting browser iOS
  iosctrl:simulator open: http://localhost:9876/?id=43904557 +1ms
  iosctrl:session start +0ms
  iosctrl:session start requested +48ms
  iosctrl:simulator _message: starting +2s

Workaround

Copy the URL from the debug output, start Safari, then paste the URL. The browser is captured and the tests run as expected.

System information

I understand this may be a /xdissent/iosctrl/ issue, but I don't have a concrete way to test this yet so I'm filing it here for now.

xdissent commented 10 years ago

Very well reported, thanks! And perfect timing - I was planning on working on this tonight.

lazd commented 10 years ago

Excellent! I look forward to testing it. Let me know when you've pushed a branch and I'll give it a whirl.

xdissent commented 10 years ago

So, it's an Xcode 5 issue with the iOS simulator. Phonegap's ios-sim (which uses a similar approach) is having the same problem: https://github.com/phonegap/ios-sim/issues/60 I did uncover a bug in iosctrl that was erroneously hiding error messages, which I'll update momentarily. The specific error I'm getting is "iOS Simulator failed to install the application."

Oh - I also clearly need to add an option to choose / autodetect the appropriate iOS simulator framework, since it's currently hardcoded to 6.1 rather than the default 7.0 for Xcode 5. If you have the 6.1 simulator installed via Xcode it should work though (but doesn't).

The only other project I know that successfully drives the iOS sim and MobileSafari is the ios-driver for selenium. I wonder if they're having the same issues with Xcode 5...

Good news is that everything's still working fine on my 10.8 machine with Xcode 4.6 =/

lazd commented 10 years ago

As an additional piece of information, when I filed I did not have the iOS 6.1 simulator installed.

xdissent commented 10 years ago

Selenium's ios-driver is working around the issue by providing a compiled-on-install iOS app that simply opens a URL in MobileSafari. I guess it's not unreasonable to assume that Xcode is available and I could probably convince node-gyp to build a similar wrapper app for us upon install, but I'd much prefer to figure out how to get the stock MobileSafari.app to launch. At least it's an option though.

xdissent commented 10 years ago

Scratch that - I was thinking of appium regarding the safari shim app. Selenium is using a clever trick that I've just confirmed to work with Xcode 5 / iOS 7: they move MobileSafari.app outside of the Xcode bundle. For some reason this allows the simulator to install the app and everything works again. The problem is, moving the app requires root perms, and simply copying it doesn't work. Investigating a simple way to visually request admin privileges for the move operation.

xdissent commented 10 years ago

If you'd like to try the xcode5 branch (https://github.com/xdissent/karma-ios-launcher/tree/xcode5) I believe I've gotten everything sorted with Xcode 5 / iOS 7. It's also working again on my Xcode 4 machine with iOS 6. I plan on merging and releasing tonight.

Odi55555 commented 10 years ago

Thx for your work, I was able to install ios-launcher from xcode5 branch. After that I tried to start the karma runner and got an error that the coffee-script module is missing. Don't know why, the install log said, that the coffee-script module was installed as a dependency of karma. After reinstalling the coffee-script module I was able to start the karma runner.

Unfortunately the iOS Sim doesn't open and no tests are executed.

$ karma start
INFO [karma]: Karma v0.10.8 server started at http://localhost:9876/
INFO [launcher]: Starting browser iOS
INFO [watcher]: Changed file "ProjectTree.js".
WARN [karma]: No captured browser, open http://localhost:9876/

I tried to get the debug output from iosctrl like you described it with

$ export DEBUG='iosctrl:*'

but nothing happens. Sorry, I don't know if the output should be displayed in my iTerm console or do I have to open a log file somewhere or read somehow the variable to see the output?

lazd commented 10 years ago

I fired this up and didn't get success either:

  iosctrl:simulator new +0ms
INFO [launcher]: Starting browser iOS
  iosctrl:simulator open: http://localhost:9876/?id=20539320 +0ms
  iosctrl:session start +0ms
  iosctrl:session start requested +29ms
  iosctrl:simulator _message: starting +1s
  iosctrl:session started +1s
  iosctrl:simulator open resolved +1s
  iosctrl:simulator _message: started +0ms

Note that the open: command comes when the simulator still shows a black screen. Maybe that has something to do with it?

I also tried with the simulator already open, it goes to a black screen and then the same result -- home screen with no browser launched :(

xdissent commented 10 years ago

@Odi55555 ah - if you install from git, it doesn't run the pre-publish npm hook and thus, doesn't get compiled to JS. That's what the coffee-script error was about anyway. Can you make sure you've got iosctrl version 0.1.1 in karma-ios-launcher/node_modules/iosctrl? Maybe npm cache clean will help.

@lazd same thing - the debug output should look something like this if you have the correct karma-ios-launcher and iosctrl:

INFO [karma]: Karma v0.10.8 server started at http://localhost:9876/
INFO [launcher]: Starting browser iOS
DEBUG [watcher]: Resolved files:
    /Users/xdissent/Code/karma-ios-launcher/example/node_modules/karma-jasmine/lib/jasmine.js
    /Users/xdissent/Code/karma-ios-launcher/example/node_modules/karma-jasmine/lib/adapter.js
    /Users/xdissent/Code/karma-ios-launcher/example/test/test.js
DEBUG [watcher]: Watching "/Users/xdissent/Code/karma-ios-launcher/example/test"
  iosctrl:simulator new +0ms { app: '/Users/xdissent/.karma-ios-launcher/7.0/MobileSafari.app',
  args: [ '-u', 'http://localhost:9876/?id=57472525' ],
  sdk: '7.0' }

The important bit is the iosctrl:simulator new line with a config object that's passed to iosctrl.

xdissent commented 10 years ago

Now that the xcode5 branch has an example, an easy way to test would be:

$ npm cache clean
$ git clone -b xcode5 https://github.com/xdissent/karma-ios-launcher
$ cd karma-ios-launcher
$ npm install
$ cd example
$ npm install
$ karma start
lazd commented 10 years ago

When I tried the above commands on my Mavericks/Xcode 5 machine, the iOS simulator doesn't launch at all. I get the following output:

DEBUG [plugin]: Loading karma-* from /Users/lazd/tmp/karma-ios-launcher/example/node_modules
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-coffee-preprocessor.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-firefox-launcher.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-html2js-preprocessor.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-requirejs.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-script-launcher.
DEBUG [plugin]: Loading inlined plugin (defining launcher:iOS).
INFO [karma]: Karma v0.10.8 server started at http://localhost:9876/
INFO [launcher]: Starting browser iOS
DEBUG [watcher]: Resolved files:
    /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-jasmine/lib/jasmine.js
    /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-jasmine/lib/adapter.js
    /Users/lazd/tmp/karma-ios-launcher/example/test/test.js
DEBUG [watcher]: Watching "/Users/lazd/tmp/karma-ios-launcher/example/test"

After a control-c, I get this:

DEBUG [launcher]: Disconnecting all browsers
ERROR [karma]: [TypeError: Cannot read property 'state' of undefined]
TypeError: Cannot read property 'state' of undefined
    at IOSLauncher.kill (/Users/lawdavis/tmp/karma-ios-launcher/lib/index.js:160:17)
    at /Users/lawdavis/tmp/karma-ios-launcher/example/node_modules/karma/lib/launcher.js:63:15
    at Array.forEach (native)
    at kill (/Users/lawdavis/tmp/karma-ios-launcher/example/node_modules/karma/lib/launcher.js:61:14)
    at EventEmitter.emit (events.js:95:17)
    at emitAsync (/Users/lawdavis/tmp/karma-ios-launcher/example/node_modules/karma/lib/events.js:68:10)
    at process.disconnectBrowsers (/Users/lawdavis/tmp/karma-ios-launcher/example/node_modules/karma/lib/server.js:127:19)
    at process.EventEmitter.emit (events.js:92:17)
    at Signal.wrap.onsignal (node.js:756:46)
DEBUG [launcher]: Disconnecting all browsers

/Users/lawdavis/tmp/karma-ios-launcher/lib/index.js:160
    if (this.sim.state === 'ready') {
                ^
TypeError: Cannot read property 'state' of undefined
    at IOSLauncher.kill (/Users/lawdavis/tmp/karma-ios-launcher/lib/index.js:160:17)
    at /Users/lawdavis/tmp/karma-ios-launcher/example/node_modules/karma/lib/launcher.js:63:15
    at Array.forEach (native)
    at kill (/Users/lawdavis/tmp/karma-ios-launcher/example/node_modules/karma/lib/launcher.js:61:14)
    at EventEmitter.emit (events.js:95:17)
    at emitAsync (/Users/lawdavis/tmp/karma-ios-launcher/example/node_modules/karma/lib/events.js:68:10)
    at disconnectBrowsers (/Users/lawdavis/tmp/karma-ios-launcher/example/node_modules/karma/lib/server.js:127:19)
    at process.<anonymous> (/Users/lawdavis/tmp/karma-ios-launcher/example/node_modules/karma/lib/server.js:152:5)
    at process.EventEmitter.emit (events.js:95:17)
    at process._fatalException (node.js:272:26)

I tested on an another machine with Xcode 4.6.3 and it worked.

xdissent commented 10 years ago

hmm, mind setting DEBUG to iosctrl:* in your shell and running karma start again?

lazd commented 10 years ago

Here's what I've got:

$ export DEBUG='iosctrl:*'
$ karma start
DEBUG [plugin]: Loading karma-* from /Users/lazd/tmp/karma-ios-launcher/example/node_modules
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-coffee-preprocessor.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-firefox-launcher.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-html2js-preprocessor.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-requirejs.
DEBUG [plugin]: Loading plugin /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-script-launcher.
DEBUG [plugin]: Loading inlined plugin (defining launcher:iOS).
INFO [karma]: Karma v0.10.8 server started at http://localhost:9876/
INFO [launcher]: Starting browser iOS
DEBUG [watcher]: Resolved files:
    /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-jasmine/lib/jasmine.js
    /Users/lazd/tmp/karma-ios-launcher/example/node_modules/karma-jasmine/lib/adapter.js
    /Users/lazd/tmp/karma-ios-launcher/example/test/test.js
DEBUG [watcher]: Watching "/Users/lazd/tmp/karma-ios-launcher/example/test"
Odi55555 commented 10 years ago

@xdissent iosctrl was already @version 0.1.1 but I uninstalled your plugin and followed your example. It seems to be the same output as @lazd posted above. I'm still on 10.8.5 with Xcode 5.0.2. Here's what I've got:

localhost:example dev$ export DEBUG='iosctrl:*'
localhost:example dev$ karma start
DEBUG [plugin]: Loading karma-* from /Users/dev/demo/karma-ios-launcher/example/node_modules
DEBUG [plugin]: Loading plugin /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-coffee-preprocessor.
DEBUG [plugin]: Loading plugin /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-firefox-launcher.
DEBUG [plugin]: Loading plugin /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-html2js-preprocessor.
DEBUG [plugin]: Loading plugin /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-requirejs.
DEBUG [plugin]: Loading plugin /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-script-launcher.
DEBUG [plugin]: Loading inlined plugin (defining launcher:iOS).
INFO [karma]: Karma v0.10.8 server started at http://localhost:9876/
INFO [launcher]: Starting browser iOS
DEBUG [watcher]: Resolved files:
    /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-jasmine/lib/jasmine.js
    /Users/dev/demo/karma-ios-launcher/example/node_modules/karma-jasmine/lib/adapter.js
    /Users/dev/demo/karma-ios-launcher/example/test/test.js
DEBUG [watcher]: Watching "/Users/dev/demo/karma-ios-launcher/example/test"

I'm getting the same errors after stopping karma:

DEBUG [launcher]: Disconnecting all browsers
ERROR [karma]: [TypeError: Cannot read property 'state' of undefined]
TypeError: Cannot read property 'state' of undefined
    at IOSLauncher.kill (/Users/dev/demo/karma-ios-launcher/lib/index.js:160:17)
    at /Users/dev/demo/karma-ios-launcher/example/node_modules/karma/lib/launcher.js:63:15
    at Array.forEach (native)
    at kill (/Users/dev/demo/karma-ios-launcher/example/node_modules/karma/lib/launcher.js:61:14)
    at EventEmitter.emit (events.js:95:17)
    at emitAsync (/Users/dev/demo/karma-ios-launcher/example/node_modules/karma/lib/events.js:68:10)
    at process.disconnectBrowsers (/Users/dev/demo/karma-ios-launcher/example/node_modules/karma/lib/server.js:127:19)
    at process.EventEmitter.emit (events.js:92:17)
    at Signal.wrap.onsignal (node.js:756:46)
DEBUG [launcher]: Disconnecting all browsers

/Users/dev/demo/karma-ios-launcher/lib/index.js:160
    if (this.sim.state === 'ready') {
                ^
TypeError: Cannot read property 'state' of undefined
    at IOSLauncher.kill (/Users/dev/demo/karma-ios-launcher/lib/index.js:160:17)
    at /Users/dev/demo/karma-ios-launcher/example/node_modules/karma/lib/launcher.js:63:15
    at Array.forEach (native)
    at kill (/Users/dev/demo/karma-ios-launcher/example/node_modules/karma/lib/launcher.js:61:14)
    at EventEmitter.emit (events.js:95:17)
    at emitAsync (/Users/dev/demo/karma-ios-launcher/example/node_modules/karma/lib/events.js:68:10)
    at disconnectBrowsers (/Users/dev/demo/karma-ios-launcher/example/node_modules/karma/lib/server.js:127:19)
    at process.<anonymous> (/Users/dev/demo/karma-ios-launcher/example/node_modules/karma/lib/server.js:152:5)
    at process.EventEmitter.emit (events.js:95:17)
    at process._fatalException (node.js:272:26)
xdissent commented 10 years ago

Each time you run it, the launcher checks for writable perms on your SDK's apps directory, so it can relocate MobileSafari.app and get it working in Xcode5. There's a popup that will request authorization if the perms haven't yet been changed. Perhaps that's popping up but you're not seeing it?

Either way, I've added more debug output and realized that Karma doesn't actually catch thrown exceptions in launchers. I have to refactor a bit more to correctly tell Karma that something went wrong if it did. Updates coming soon.

mkcode commented 10 years ago

Same problem here. I could be way off base here, but perhaps this is related to the changes made in Mavericks to how accessibility permissions work? I've seen a number of apps have this problem. Does anyone have this working correctly on osx Mavericks?

https://developer.apple.com/library/mac/releasenotes/General/APIDiffsMacOSX10_9/AppKit.html

mkcode commented 10 years ago

but if that's the case - it should solved in the underlying iosctrl package...

fatso83 commented 10 years ago

I cannot seem to find a related issue in the underlying iosctrl package. Is the status of this issue resolved, or is there a need for more testdata for the cases where it doesn't work?

fatso83 commented 10 years ago

The permissions dialog seem to work fine as you can see from the screenshots: permissions dialog

And the permissions seem to be fine afterwards:

$ for path in `locate '*MobileSafari.app'`; do v -d $(dirname $path); done
drwxrwxr-x  19 root  admin  646 Apr 17  2012 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/Applications
drwxrwxr-x  32 root  admin  1088 May 28  2013 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/Applications
drwxrwxrwx  37 root  wheel  1258 Nov 13 14:30 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/Applications

But alas, I too just get the same results as Odi55555 (https://github.com/xdissent/karma-ios-launcher/issues/2#issuecomment-30303522)

clkao commented 10 years ago

This helper works for launching safari within ios-sim with specific url: https://github.com/rockitbaby/IOSSimulatorSafariLauncher