11

I'm really can't find any example of using x-ray and .driver(phantom()) for authentication.. I've trawled through the documentation for x-ray and x-ray-phantom yet can't find any help.

Rentrop
  • 20,979
  • 10
  • 72
  • 100
Babra Cunningham
  • 2,949
  • 1
  • 23
  • 50
  • 1
    It doesn't look like x-ray was designed for that. I see no way to type something into the page. It seems you can use the `request()` method which I found in the code. – Artjom B. Oct 22 '15 at 19:48

1 Answers1

4
/**
 * Module Dependencies
 */

var Crawler = require('x-ray-crawler');
var cheerio = require('cheerio');
var join = require('path').join;
var assert = require('assert');
var phantom = require('../');
var fs = require('fs');

/**
 * Tests
 */

describe('phantom driver', function() {

  it('should have sensible defaults', function(done) {
    var crawler = Crawler()
      .driver(phantom())

    crawler('http://google.com', function(err, ctx) {
      if (err) return done(err);
      var $ = cheerio.load(ctx.body);
      var title = $('title').text();
      assert.equal('Google', title);
      done();
    })
  });

  it('should work with client-side pages', function(done) {
    var crawler = Crawler()
      .driver(phantom());

    crawler('https://exchange.coinbase.com/trade', function(err, ctx) {
      if (err) return done(err);
      var $ = cheerio.load(ctx.body);
      var price = $('.market-num').text();
      assert.equal(false, isNaN(+price));
      done();
    })
  })

  it('should support custom functions', function(done) {
    var crawler = Crawler()
      .driver(phantom(runner));

    crawler('http://mat.io', function(err, ctx) {
      if (err) return done(err);
      var $ = cheerio.load(ctx.body);
      var title = $('title').text();
      assert.equal('Lapwing Labs', title);
      done();
    })

    function runner(ctx, nightmare) {
      return nightmare
        .goto(ctx.url)
        .click('.Header-logo-item+ .Header-list-item a')
        .wait()
    }
  })
})

/**
 * Read
 */

function get(path) {
  return require(join(__dirname, 'fixtures', path));
}

Refer below github links if it helps.

  1. https://github.com/lapwinglabs/x-ray-phantom
  2. https://github.com/lapwinglabs/x-ray/issues/22
Pratiyush Kumar Singh
  • 1,977
  • 3
  • 19
  • 39