I have looked at the Appium code samples and I do not understand how to import/export my functions. I am trying to clean up some of my code and pull out the functions into separate modules, but I am having a terrible time. To try to keep it short and simple ill just show one example of a function and if we can get one to work I can get the rest.
So I have two files testScript.js and functionHelpers.js. I am just trying to click the sign in button on the app so in testScript.js my code looks like…
let func = require(‘./functionHelpers.js’);
function clickByName(name) {
return driver
.elementByName(name)
.click();
}
it("Click Sign In button", function () {
return clickByName('Sign In')
.waitForElementByName('Sites', 3000000,1000)
});
But I would like to pull that function out in functionHelpers.js and this is what I currently have…
"use strict"
let wd = require('wd'),
driver;
exports.clickByName = function(name) {
return driver.elementByName(name)
.click();
}
I thought this would work and if I console.log(func) I see the output of my function being inside of an object so I know the path is correct and its being seen. I have seen errors like driver is not defined but the current error I am getting is
return driver.elementByName(name)
^
TypeError: Cannot read property 'elementByName' of undefined
I feel like I am real close but I must be missing something important. Once again I really appreciate any help you can give me.