2016-12-08 6 views
1

分度器 - キュウリフレームワークを使用してモナコエディタのBDDテストを作成しています。しばらく前に、私はMonaco APIについて、そしてエディタ内の値をプログラムで設定する方法について知りました。しかし、今回は、 分度器を使ってモナコのエディター内のテキストを取得できません。私のコードのサンプルは次のとおりです。分度器を使用してモナコエディタ内のテキストを取得できません

browser.ignoreSynchronization = true; 
     let driver = browser.driver; 
     // iframe ids 

     let iframeID = 'editorFrame'; 

     let editorSpanXpath = '//div[@id="editorContainer"]//div[contains(@class, "monaco- editor")]//div[contains(@class, "editor-scrollable")]' 
     // switching to the iFrame to perform tasks inside it 
     browser.switchTo().frame(iframeID); 

    // clicking on a div inside the editor to ascertain that 
    // the browser knows where to run the script 

     driver.findElement(by.xpath(editorSpanXPath)).click(); 
     browser.executeScript('this.monaco.editor.getModels()[0].getValue()').then(function(editorText){ 
       let replaceString = 'abracadbra' + editorText 
       browser.executeScript('this.monaco.editor.getModels()[0].setValue("' + replaceString + '")'); 
     } 
     ); 

ここでの問題は、「editorText」の値がnullになることです。私のBDDテストを実行すると、エディタ内の値は'abracadabranull'に置き換えられます

エディタはいくつかのデフォルトテキストで初期化されています。また、 'setValue'関数が動作しているので、ブラウザのドライバはエディタがロードされるiFrameを取得するのに問題がないことがわかります。

ご協力いただければ幸いです。最後に

答えて

0

は、それが一日保存されたシンプルなreturn文だった:正しい方向に私を指しているためthis答えに

browser.ignoreSynchronization = true; 
    let driver = browser.driver; 
    // iframe ids 

    let iframeID = 'editorFrame'; 

    let editorSpanXpath = '//div[@id="editorContainer"]//div[contains(@class, "monaco- editor")]//div[contains(@class, "editor-scrollable")]' 
    // switching to the iFrame to perform tasks inside it 
    browser.switchTo().frame(iframeID); 

// clicking on a div inside the editor to ascertain that 
// the browser knows where to run the script 

    driver.findElement(by.xpath(editorSpanXPath)).click(); 
    browser.executeScript('return this.monaco.editor.getModels()[0].getValue()').then(function(editorText){ 
      let replaceString = 'abracadbra' + editorText 
      browser.executeScript(' return this.monaco.editor.getModels()[0].setValue("' + replaceString + '")'); 
    } 
    ); 

感謝します。

関連する問題