3

I am trying to execute javascript Appium test using WD. My code should look something like this:

"use strict";

var wd = require("wd");
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
var jQuery = require("jQuery");

chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var desired = {
    "appium-version": "1.0",
    platformName: "iOS",
    platformVersion: "7.1",
    deviceName: "iPhone Retina (3.5-inch)",
    app: "/Users/{myuser}/Library/Developer/Xcode/DerivedData/{MyApp}/Build/Products/Debug-iphonesimulator/MyApp.app",
};

var browser = wd.promiseChainRemote("0.0.0.0", 4723);


browser.init(desired).then(function() {

    var getIframe = function(){
        //var r = jQuery('#myIframe');
        return {'response':"1"};//only for testing that this method works...
    };

    return browser

        .elementByName("Show Webview").click()
        .sleep(10000)
        .contexts().then(function (contexts) { // get list of available views. Returns array: ["NATIVE_APP","WEBVIEW_1"]
            return browser.context(contexts[1]); // choose the webview context
        })
        .execute(getIframe).then(function(res){
            console.log(res);
        })
        .sleep(10000)
        .fin(function() {
            //return browser.quit();
        });
}, function(e){console.log(e);}).done(); 

I am running this code using node mytest.js.

The problem is that I cannot execute js code. In this case I am getting the following error:

Error: [execute()] Not JSON response

What am I doing wrong?

Comments:

  1. What I finally am trying to do here is access and manipulate an iFrame in my code (in the same domain), using iFrame.contentDocument

  2. My insperation for using 'execute like this is from this post

tnx, Yaniv

UPDATE:

I have managed to execute javascript using "safeExecute" method, instead of "execute". My issue now is that I do not have access to "window" object, so I cannot run "jQuery" or "window.document.getElementById"...

Community
  • 1
  • 1
Yaniv Efraim
  • 6,633
  • 7
  • 53
  • 96

0 Answers0