Reputation: 175
I have a problem with accessing code that I am able to use through browser console.
In my case it is a Tawk_Api function Tawk_API.hideWidget();
I tried to use browser execute and call but the output saying that Tawk.Api is not defined
Code example
var expect = require('chai').expect;
function HideTawk (){
Tawk_API.hideWidget();
}
describe('', function() {
it('should be able to filter for commands', function () {
browser.url('https://arutech.ee/en/windows-price-request');
$('#uheosaline').click();
browser.execute(HideTawk());
var results = $$('.commands.property a').filter(function (link) {
return link.isVisible();
});
expect(results.length).to.be.equal(3);
results[1].click();
expect($('#getText').getText()).to.be.equal('GETTEXT');
});
});
Working fixed function:
function HideTawk (){
return new Promise(function(resolve, reject) {
Tawk_API.hideWidget();
})
}
And browser.execute(HideTawk())
is a mistake it should be browser.call(HideTawk());
docs: http://webdriver.io/api/utility/call.html
Upvotes: 1
Views: 634
Reputation: 1184
I have a below code in my application base object it can help you to understand call api:
_callClientAPI(func, args) {
let trial = 1;
return new Promise(async(res, rej) => {
while (true) {
if (trial > this._pollTrials) {
rej(`Could not retrieve the element in this method * this._pollTimeout} seconds.`);
break;
}
let result;
try {
result = await func.call(this.client, args, false);
} catch (e) { }
if (result && result !== '') {
res(result);
break;
}
await this.wait();
trial++;
}
});
}
Upvotes: 1