Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added encodedSync to get profiles using a Sync method #10

Closed
wants to merge 1 commit into from
Closed

Added encodedSync to get profiles using a Sync method #10

wants to merge 1 commit into from

Conversation

axemclion
Copy link

I am using this in karma-sauce-launcher and it is much easier to get the profile if it is available synchronously.

fp.setPreference('extensions.firebug.defaultPanelName', 'console');
fp.updatePreferences();
fp.addExtensions(testProfile.extensions, function() {
var zippedProfile = fp.encodedSync();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an "SyntaxError: Unexpected end of input", because of an indentation problem here. See other comments at the end of this file.

@axemclion
Copy link
Author

Aaargh .... copy-paste error. I was editing from the npm module and pasted it here, sorry.

// because table method is probably added to the regular console
.eval('console.table').then(function(res) {
res.should.contain('function');
sendStatusToSauceLabs(browser.sessionID, true, function() { done(); });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done() is called here but not defined in the 'it()' callback

@axemclion
Copy link
Author

Fixed and sent in a new pull request.

@saadtazi
Copy link
Owner

Thanks for your pull request.

The build failed for a couple of reasons:

  • syntax error (see my comment)
  • done not defined but called by the test you added (see my comment)
  • admZip generates invalid zip when one of the file in an extension is a png

The last point is a show stopper: see cthackers/adm-zip#57.
I actually switched to archiver because of that bug: #4

the error I get:

Error: The environment you requested was unavailable.
      at Request._callback (/Users/saadtazi/Projects/firefox-profile-js/node_modules/wd/lib/webdriver.js:316:15)
      at Request.self.callback (/Users/saadtazi/Projects/firefox-profile-js/node_modules/wd/node_modules/request/index.js:148:22)
      at Request.EventEmitter.emit (events.js:98:17)
      at Request.<anonymous> (/Users/saadtazi/Projects/firefox-profile-js/node_modules/wd/node_modules/request/index.js:876:14)
      at Request.EventEmitter.emit (events.js:117:20)
      at IncomingMessage.<anonymous> (/Users/saadtazi/Projects/firefox-profile-js/node_modules/wd/node_modules/request/index.js:827:12)
      at IncomingMessage.EventEmitter.emit (events.js:117:20)
      at _stream_readable.js:920:16
      at process._tickCallback (node.js:415:13)

And the selenium server outputs the following:

    ... 9 more
Caused by: org.openqa.selenium.WebDriverException: java.util.zip.ZipException: invalid code lengths set
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9', java.version: '1.7.0_21'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.firefox.FirefoxDriver.extractProfile(FirefoxDriver.java:134)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:107)
    ... 14 more
Caused by: java.util.zip.ZipException: invalid code lengths set
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
    at java.util.zip.ZipInputStream.read(ZipInputStream.java:193)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at org.openqa.selenium.io.Zip.unzipFile(Zip.java:170)
    at org.openqa.selenium.io.Zip.unzip(Zip.java:152)
    at org.openqa.selenium.io.Zip.unzip(Zip.java:123)
    at org.openqa.selenium.firefox.FirefoxProfile.fromJson(FirefoxProfile.java:421)
    at org.openqa.selenium.firefox.FirefoxDriver.extractProfile(FirefoxDriver.java:132)
    ... 15 more
20:45:26.628 WARN - Exception: invalid code lengths set

But if you find another module that can generate valid zips in a synchronous way I will be happy to accept another pull request (I will do some research on my side, but I didn't find anything a couple of weeks ago).

To make sure that it works, I think the easiest way is to:

  • start selenium server locally
  • fix the syntax error
  • add ".only" to your test (it(--> `ìt,only(``) so you only run that test
  • remove the params to wd.promiseChainRemote() call to hit the local selenium server
  • run ```mocha test/spec/extension.js

I am sorry but i can't accept that pull request as-is.

As a side note:

When using karma-sauce-launcher, I think you can do the following:

var FirefoxProfile = require('firefox-profile');

module.exports = function(config) {
  var myProfile = new FirefoxProfile();
  // if you ned an extension
  myProfile.addExtension('test/extensions/firebug-1.12.4-fx.xpi', function() {
    var capabilities = webdriver.Capabilities.firefox();
    // attach your newly created profile
    myProfile.encoded(function(encodedProfile) {

      config.set({
        customLaunchers: {
          ...
          custFirefox: {
            base: 'SauceLabs',
            browserName: 'chrome',
            platform: 'linux',
            firefox_profile: encodedProfile
         }

@saadtazi
Copy link
Owner

I tried the following, after reading a comment in cthackers/adm-zip#65:

FirefoxProfile.prototype.encodedSync = function(){
  var self = this, files = wrench.readdirSyncRecursive(this.profileDir);
  var zip = new AdmZip();

  files.forEach(function(filePath) {
    if (fs.statSync(path.join(self.profileDir, filePath)).isFile()) {
      zip.addLocalFile(path.join(self.profileDir, filePath));
    }
  });
  var zipEntries = zip.getEntries(); // an array of ZipEntry records
  //https://github.com/cthackers/adm-zip/issues/65
  zipEntries.forEach(function(zipEntry) {
    zipEntry.header.method = 0;
  });
  return zip.toBuffer().toString('base64');
}

The browser starts but the profile is not correctly loaded (no extensions or userPrefs)...

@axemclion
Copy link
Author

Makes sense - will close this and send in a new request later.

For the karma tests, the config.set needs to happen immediately, else karma for some reason does not see the config and does not run.

@axemclion axemclion closed this Nov 23, 2013
@saadtazi
Copy link
Owner

Oh, I see, config.set() cannot be called asynchronously (in a callback).

If you are using grunt-karma, then something similar to this might help (assuming that customLauchners option is supported by grunt-karma in Gruntfile.js): http://stackoverflow.com/questions/16547528/how-can-i-perform-an-asynchronous-operation-before-grunt-initconfig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants