'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();
  });

});

@@ -156,16 +156,52 @@
 ase();%0A%0A
+const pkg = require('../package');%0A%0A
 const iO
@@ -968,121 +968,110 @@
    .
-elementById('index-kw')%0A      .sendKeys('macaca')%0A      .elementById('index-bn')%0A      .click()%0A      .sleep(5000
+sleep(10 * 1000)%0A      .title()%0A      .then(title =%3E %7B%0A        console.log(%60title: $%7Btitle%7D%60);%0A      %7D
 )%0A  
@@ -1067,38 +1067,35 @@
       %7D)%0A      .
-source
+url
 ()%0A      .then(h
@@ -1085,35 +1085,34 @@
 l()%0A      .then(
-htm
+ur
 l =%3E %7B%0A        h
@@ -1114,39 +1114,33 @@
     
-html.should.containEql('macaca'
+console.log(%60url: $%7Burl%7D%60
 );%0A 
@@ -1158,131 +1158,196 @@
    .
-takeScreenshot
+refresh
 ()
-;
 %0A  
-%7D);%0A%0A  it('#1 should works with web', function() %7B%0A    return driver%0A      .get('https://www.baidu.com'
+    .sleep(2000)%0A      .elementById('index-kw')%0A      .getProperty('name')%0A      .then(info =%3E %7B%0A        console.log(%60get web attribute name: $%7BJSON.stringify(info)%7D%60);%0A      %7D
 )%0A  
@@ -1343,33 +1343,40 @@
       %7D)%0A      .
-e
+waitForE
 lementById('inde
@@ -1399,16 +1399,19 @@
 ndKeys('
+%E4%B8%AD%E6%96%87+
 Macaca')
@@ -1561,24 +1561,110 @@
 );%0A      %7D)%0A
+      .execute(%60document.body.innerHTML = %22%3Ch1%3E$%7Bpkg.name%7D%3C/h1%3E%22%60)%0A      .sleep(3000)%0A
       .takeS

tweak getSource