/*global it:true */
"use strict";

var path = require('path')
  , appPath = path.resolve(__dirname, "../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk")
  , appPkg = "com.example.android.apis"
  , appAct = ".ApiDemos"
  , describeWd = require("../../helpers/driverblock.js").describeForApp(appPath,
      "android", appPkg, appAct)
  , should = require('should');

describeWd('get attribute', function(h) {
  it('should be able to find text attribute', function(done) {
    h.driver.elementByName('Animation', function(err, el) {
      should.not.exist(err);
      el.getAttribute('text', function(err, text) {
        should.not.exist(err);
        text.should.equal("Animation");
        done();
      });
    });
  });
  it('should be able to find name attribute', function(done) {
    h.driver.elementByName('Animation', function(err, el) {
      should.not.exist(err);
      el.getAttribute('name', function(err, text) {
        should.not.exist(err);
        text.should.equal("Animation");
        done();
      });
    });
  });
  it('should be able to find name attribute, falling back to text', function(done) {
    h.driver.elementByName('Animation', function(err, el) {
      should.not.exist(err);
      el.click(function(err) {
        should.not.exist(err);
        h.driver.elementsByTagName('text', function(err, els) {
          should.not.exist(err);
          els[1].getAttribute('name', function(err, text) {
            should.not.exist(err);
            text.should.equal("Bouncing Balls");
            done();
          });
        });
      });
    });
  });
  it('should be able to find displayed attribute', function(done) {
    h.driver.elementByName('Animation', function(err, el) {
      should.not.exist(err);
      el.getAttribute('displayed', function(err, val) {
        should.not.exist(err);
        val.should.equal(true);
        done();
      });
    });
  });
  it('should be able to find displayed attribute through normal func', function(done) {
    h.driver.elementByName('Animation', function(err, el) {
      should.not.exist(err);
      el.displayed(function(err, val) {
        should.not.exist(err);
        val.should.equal(true);
        done();
      });
    });
  });
  it('should be able to get element location', function(done) {
    h.driver.elementByName('Animation', function(err, el) {
      should.not.exist(err);
      el.getLocation(function(err, loc) {
        should.not.exist(err);
        [0].should.include(loc.x);
        [183].should.include(loc.y);
        done();
      });
    });
  });
  // TODO: tests for checkable, checked, clickable, focusable, focused,
  // longClickable, scrollable, selected
});

@@ -2672,12 +2672,1190 @@
 elected%0A%7D);%0A
+%0AdescribeWd('get attribute selected', function(h) %7B%0A  it('should be able to get selected value of a tab', function(done) %7B%0A  h.driver.execute(%22mobile: find%22, %5B%5B%22scroll%22,%5B%5B3, %22views%22%5D%5D,%5B%5B7, %22views%22%5D%5D%5D%5D, function(err, el) %7B%0A    should.not.exist(err);%0A    el.click(function(err) %7B%0A    h.driver.execute(%22mobile: find%22, %5B%5B%22scroll%22,%5B%5B3, %22tabs%22%5D%5D,%5B%5B7, %22tabs%22%5D%5D%5D%5D, function(err, el) %7B%0A      should.not.exist(err);%0A      el.click(function(err) %7B%0A      h.driver.execute(%22mobile: find%22, %5B%5B%22scroll%22,%5B%5B3, %22content by id%22%5D%5D,%5B%5B7, %22content by id%22%5D%5D%5D%5D, function(err, el) %7B%0A        should.not.exist(err);%0A        el.click(function(err) %7B%0A        h.driver.elementsByTagName(%22text%22, function(err,els) %7B%0A          should.not.exist(err);%0A          els%5B0%5D.getAttribute('selected', function(err, selected) %7B%0A          should.not.exist(err);%0A          selected.should.equal(false); // the 1st text is not selected%0A          els%5B1%5D.getAttribute('selected', function(err, selected) %7B%0A            should.not.exist(err);%0A            selected.should.equal(true); // tab 1 is selected%0A            done();%0A          %7D);%0A          %7D);%0A        %7D);%0A        %7D);%0A      %7D);%0A      %7D);%0A    %7D);%0A    %7D);%0A  %7D);%0A  %7D);%0A%7D);%0A

Add test