JSファイルにあるTakeScreenshot関数を記述しました。base.jsファイルと呼ばれるスクリーンショットを保存し、スクリーンショットのパスを返します。エラーの取得mesasge "this.TakeScreenshotは分度器の関数ではありません"
this.TakeScreenshot = function(screenShotName) {
//some stuff.....
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream(screenshotPath);
stream.write(new Buffer(png, 'base64'));
stream.end();
});
return screenshotPath;
};
I am calling the above function in another function called "isTruelyPresent". This function will take a screenshot if element is present/not present on UI. The implementation is as below:
this.isTrulyPresent = function(elementToCheckVisibilityOf, element2) {
return elementToCheckVisibilityOf.isDisplayed().then(function (isDisplayedd) {
var myObj;
myObj = this.TakeScreenshot(element2);
// some stuff
console.log('isDisplayed'+isDisplayedd);
return isDisplayedd;
}).then(null, function (error) {
var myObj;
myObj = this.TakeScreenshot("ErrorSS");
console.log('A NoSuchElement exception was throw because the element is NOT displayed so we return false');
return false;
});
};
Protractor script is throwing an error "this.TakeScreenshot is not a function". Could any one please help me to resolve the issue.
注:非同期プログラミングでisTrulyPresent関数が同じJSファイル(base.js) –
に存在する場合、コールバックメソッドで 'this'キーワードを使用することはできません。その代わりに、関数スコープ内に新しい変数を宣言し、新しく作成された変数に 'this'を割り当てます。あなたのケースでは、 'isTrulyPresent'メソッドの中で' var self = this; 'のような変数を作り、' self.TakeScreenshot() 'を使ってメソッドを呼び出します。 –
ありがとう@SudharsanSelvaraj ..あなたの助けが大変ありがとうございます。私はあなたの解決策を試し、私は何か問題がある場合はあなたに戻って取得します。ありがとう、たくさんの友達。 –