'use strict';

require('should');
const _ = require('macaca-utils');

var browserName = process.env.browser || 'safari';
browserName = browserName.toLowerCase();

const iOSSafariOpts = {
  deviceName: 'iPhone 6',
  platformName: 'iOS',
  browserName: 'Safari'
};

const AndroidChromeOpts = {
  platformName: 'Android',
  browserName: 'Chrome'
};

const wd = require('macaca-wd');

describe('macaca mobile sample', function() {
  this.timeout(5 * 60 * 1000);

  var driver = wd.promiseChainRemote({
    host: 'localhost',
    port: 3456
  });

  driver.configureHttp({
    timeout: 600 * 1000
  });

  before(function() {
    return driver
      .init(browserName === 'safari' ? iOSSafariOpts : AndroidChromeOpts)
      .sleep(10 * 1000);
  });

  after(function() {
    return driver
      .sleep(1000)
      .quit();
  });

  it('#0 should works with macaca', function() {
    return driver
      .get('https://www.baidu.com')
      .elementById('index-kw')
      .sendKeys('macaca')
      .elementById('index-bn')
      .click()
      .sleep(5000)
      .source()
      .then(html => {
        html.should.containEql('macaca');
      })
      .takeScreenshot();
  });

  it('#1 should works with web', function() {
    return driver
      .get('https://www.baidu.com')
      .elementById('index-kw')
      .sendKeys('Macaca')
      .elementById('index-bn')
      .click()
      .sleep(5000)
      .source()
      .then(html => {
        html.should.containEql('Macaca');
      })
      .takeScreenshot();
  });

});

'use strict';

require('should');
const _ = require('macaca-utils');

var browserName = process.env.browser || 'safari';
browserName = browserName.toLowerCase();

const pkg = require('../package');

const iOSSafariOpts = {
  deviceName: 'iPhone 6',
  platformName: 'iOS',
  browserName: 'Safari'
};

const AndroidChromeOpts = {
  platformName: 'Android',
  browserName: 'Chrome'
};

const wd = require('macaca-wd');

describe('macaca mobile sample', function() {
  this.timeout(5 * 60 * 1000);

  var driver = wd.promiseChainRemote({
    host: 'localhost',
    port: 3456
  });

  driver.configureHttp({
    timeout: 600 * 1000
  });

  before(function() {
    return driver
      .init(browserName === 'safari' ? iOSSafariOpts : AndroidChromeOpts)
      .sleep(10 * 1000);
  });

  after(function() {
    return driver
      .sleep(1000)
      .quit();
  });

  it('#0 should works with macaca', function() {
    return driver
      .get('https://www.baidu.com')
      .sleep(10 * 1000)
      .title()
      .then(title => {
        console.log(`title: ${title}`);
      })
      .url()
      .then(url => {
        console.log(`url: ${url}`);
      })
      .refresh()
      .sleep(2000)
      .elementById('index-kw')
      .getProperty('name')
      .then(info => {
        console.log(`get web attribute name: ${JSON.stringify(info)}`);
      })
      .waitForElementById('index-kw')
      .sendKeys('中文+Macaca')
      .elementById('index-bn')
      .click()
      .sleep(5000)
      .source()
      .then(html => {
        html.should.containEql('Macaca');
      })
      .execute(`document.body.innerHTML = "<h1>${pkg.name}</h1>"`)
      .sleep(3000)
      .takeScreenshot();
  });

});

tweak getSource