chenglou / node-huxley

Codeless front-end testing.
MIT License
361 stars 29 forks source link

Option to specify browser #1

Open chenglou opened 11 years ago

chenglou commented 11 years ago
jhnns commented 10 years ago

I could test ie. Is there already an option?

Concerning mobile devices: Are touchevents supported?

chenglou commented 10 years ago

Humm, after all the browsers instability with selenium I think I'll leave that to third party for now. Right now you can inject your own driver so this shouldn't be a problem. For touchevents: no, not yet.

jhnns commented 10 years ago

K, thx.

robdodson commented 10 years ago

I'm a total selenium newb but I started down the path of trying to add in iphone support. Here's what I've added to node-huxley: https://github.com/robdodson/node-huxley/commit/938ffc34a386dac0ee7b4564afd3d5f041545853

When I run the ios-driver, it does start up the emulator, but then it crashes with this error:

$ hux -b iphone -r

/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/promise.js:1549
      throw error;
            ^
UnknownError: undefined
    at new bot.Error (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
    at Object.bot.response.checkResponse (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/atoms/response.js:103:11)
    at /Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:276:20
    at /Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/goog/base.js:1178:15
    at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/promise.js:1445:20)
    at notify (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/promise.js:328:12)
    at notifyAll (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/promise.js:297:7)
    at fulfill (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/promise.js:402:7)
    at /Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/promise.js:1312:10
    at /Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/goog/base.js:1178:15
==== async task ====
WebDriver.manage().window().setSize(750, 572)
    at webdriver.WebDriver.schedule (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:267:15)
    at webdriver.WebDriver.Window.setSize (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:1240:23)
    at Object.goToUrl (/Users/robdodson/Desktop/node-huxley/source/browser/driver.js:73:6)
    at _runActionOrDisplaySkipMsg (/Users/robdodson/Desktop/node-huxley/index.js:149:11)
    at _runEachPlayback (/Users/robdodson/Desktop/node-huxley/index.js:56:3)
    at /Users/robdodson/Desktop/node-huxley/index.js:113:7
    at _open (/Users/robdodson/Desktop/node-huxley/source/browser/driver.js:35:3)
    at Object.open (/Users/robdodson/Desktop/node-huxley/source/browser/driver.js:52:3)
    at _openRunAndClose (/Users/robdodson/Desktop/node-huxley/index.js:76:11)

Any ideas?

chenglou commented 10 years ago

Looks like setSize()? What happens if you comment out the 2 setSize here?

robdodson commented 10 years ago

This version of driver.js gets us much closer (https://github.com/robdodson/node-huxley/blob/e00ea0b39f90408108e80aecc8ead9e7ae2a1a40/source/browser/driver.js). I'm able to open my site, and press enter in terminal (although it doesn't look like it recorded any snapshots yet). Now it dies when it tries to do the playback.

Don't move! Simulating the recording now...

iphone opening.

At 1 type and toggle.hux

/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/promise.js:1549
      throw error;
            ^
SessionNotCreatedError: {platform=MAC, locale=en_GB, CFBundleName=Safari, device=iphone} no devices available.
    Known devices: [Simulator[in use by ios-driver]]
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'N/A', ip: 'N/A', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.3', java.version: '1.7.0_55'
Driver info: driver.version: unknown
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'N/A', ip: 'N/A', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.3', java.version: '1.7.0_55'
Driver info: driver.version: unknown
    at new bot.Error (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
    at Object.bot.response.checkResponse (/Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
    at /Users/robdodson/Desktop/node-huxley/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:134:24
chenglou commented 10 years ago

Man, never trust Selenium... Honestly I have no idea what's happening here. This is the main reason why I've refrained from supporting anything other than FF and Chrome for now (and even two is a bit of hassle). The bits I got from Selenium all came from reading the source code =(

robdodson commented 10 years ago

Hm this might be interesting...

I started following the errors and logging the responseObj that's handed to checkResponse

Here's what I see when I'm just clicking around in record mode:

Begin record
Type q to quit, l for taking a screenshot and marking a live playback point til next screenshot, and anything else to take a normal screenshot.
> { sessionId: 'c79917fd-0afe-43e7-a317-bbb78ecef8b7',
  status: 0,
  value: null,
  state: null,
  class: 'org.openqa.selenium.remote.Response',
  hCode: 1946879818 }

1 screenshot recorded.

Here's what I see when it enters playback mode:

Don't move! Simulating the recording now...

iphone opening.

At 1 type and toggle.hux
{ sessionId: '11b5145d-2816-4e60-980b-4322c2ba563f',
  status: 0,
  value: '',
  state: null,
  class: 'org.openqa.selenium.remote.Response',
  hCode: 1153794846 }
{ sessionId: '',
  status: 33,
  value:
   { message: '{platform=MAC, locale=en_GB, CFBundleName=Safari, device=iphone} no devices available.\n    Known devices: [Simulator[in use by ios-driver]]\nBuild info: version: \'unknown\', revision: \'unknown\', time: \'unknown\'\nSystem info: host: \'N/A\', ip: \'N/A\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.9.3\', java.version: \'1.7.0_55\'\nDriver info: driver.version: unknown\nBuild info: version: \'unknown\', revision: \'unknown\', time: \'unknown\'\nSystem info: host: \'N/A\', ip: \'N/A\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.9.3\', java.version: \'1.7.0_55\'\nDriver info: driver.version: unknown',
     screen: null,
     cause:
      { message: '{platform=MAC, locale=en_GB, CFBundleName=Safari, device=iphone} no devices available.\n    Known devices: [Simulator[in use by ios-driver]]\nBuild info: version: \'unknown\', revision: \'unknown\', time: \'unknown\'\nSystem info: host: \'N/A\', ip: \'N/A\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.9.3\', java.version: \'1.7.0_55\'\nDriver info: driver.version: unknown',
        screen: null,
        class: 'org.openqa.selenium.SessionNotCreatedException',
        stackTrace: [Object] },
     class: 'org.openqa.selenium.SessionNotCreatedException',
     stackTrace:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] },
  state: null,
  class: 'org.openqa.selenium.remote.Response',
  hCode: 1546879979 }

The main thing I noticed was the message it returned:

no devices available.\n    Known devices: [Simulator[in use by ios-driver]]

and that there seems to be two sessions at play there. One seems to open up selenium just fine, the second seems to be blocked in some way

chenglou commented 10 years ago

Oh... that must be openDummy. I open a dummy window on desktop to steal the focus of the main window for consistent focus behaviour. Guess that's backfiring.

Can you try commenting this out? https://github.com/chenglou/node-huxley/blob/master/index.js#L87

robdodson commented 10 years ago

I was able to get a bit further by disabling the openDummy command (https://github.com/robdodson/node-huxley/commit/34b35a531ef288025bf808409d13ee1ca180dff7). It seems like that command is intended to open a second session to steal focus from the main session but I don't think the iOS simulator allows multiple sessions.

Btw, quick aside, thank you for commenting the code so well. It's quite easy to navigate

This will start to play back the recorded bits, but I've noticed it just zooms in the text field, enters one letter, and dies again. Saying: The tests now halt. You might have unfinished tasks.

robdodson commented 10 years ago

OK, so...

If I only use clicks I can get a complete playback. For instance, starting a recording, clicking on the checkbox, hitting enter then q. That plays back fine.

Also, hitting l, clicking the modal, hitting l then enter. That plays back as well.

So it seems like the issue is with keypressing and maybe the keypress events themselves...

robdodson commented 10 years ago

Hah funny... so when I just run hux -b iphone it fails because the screencap captures the clock at the top of the simulator and the times differ.

diff

robdodson commented 10 years ago

Working on a fix by adding a condition inside of simulateScreenshot.js. Gotta figure out if that bar hides itself if the user is scrolling down the page :\

chenglou commented 10 years ago

Here's the keypress file, I'm simply proxying it to Selenium.

The clock issue is easy to solve. I did a similar thing for Chrome/FF: https://github.com/chenglou/node-huxley/blob/master/source/constants.js

BTW, I might not officially support iOS in a near future. Better not supporting it than fixing stuff I don't understand lol. Selenium is weird.

Though you shouldn't have too much of a hard time if you ever need to maintain a fork: openDummy is likely going away (#65). setSize probably errored on the dummy (can you de-comment out the setSize in goToUrl to verify?) and screenshot cropping shouldn't be a bother. Key input, dunno yet.

chenglou commented 10 years ago

For bar hiding, you could use iOS' new minimal UI meta tag. Hope that works.

robdodson commented 10 years ago

The clock issue is easy to solve. I did a similar thing for Chrome/FF: https://github.com/chenglou/node-huxley/blob/master/source/constants.js

Just configuring the top of the screenshot to be down 50px seemed to chop off the clock ok.

BTW, I might not officially support iOS in a near future. Better not supporting it than fixing stuff I don't understand lol. Selenium is weird.

I hear you, but I think supporting mobile browsers would be worth the investment in time. The future of the web is on mobile devices and we're desperate to have tools to help out with this.

setSize probably errored on the dummy (can you de-comment out the setSize in goToUrl to verify?)

This still blows up if I comment those lines back in. It doesn't seem to be an issue at the moment because the simulator is always the same size (for me at least).

chenglou commented 10 years ago

I'll hopefully be updating huxley during the weekend. I'll see

robdodson commented 10 years ago

hm, ok new hurdle... Even though I see the playback performing the correct actions, they're not captured in the screenshots. For instance, if I uncheck a checkbox in record, then I see it uncheck during playback, but the captured screenshot still shows it as checked.

Wondering if everything should wait 300ms before doing a screenshot. I believe that's the built in lag on iOS for touch actions

robdodson commented 10 years ago

OK, got my first successful, repeatable iphone test! Adding 300ms delay to all clicks fixed my screenshotting issue.

chenglou commented 10 years ago

Ahahaha oh wow... iOS 8 removes the delay conditionally. Not sure if you'll still need it soon?