15

次の html 構造を生成するディレクティブがあります。

<div class="popover ng-isolate-scope" ng-mouseover="toggle(true)" ng-mouseleave="toggle(false)" popover="" label="hover time!" trigger-class="button" content-class="specialContentClass">  
  <span id="thing" class="popover-trigger button">hover time!</span>
  <div ng-transclude="" ng-show="show" class="popover-content ng-hide">
    <div class="ng-scope">Popover content </div>
  </div>
</div>

コードは正常に動作し、ブラウザーを使用して手動でマウスオーバーすると、ポップオーバー コンテンツが正しく表示されます。

次の分度器テストでマウスオーバー機能をテストしようとしています:

 it('should display the popover-content on mouseover', function() {
     browser.get('http://localhost:9000/');
     browser.actions()
     .mouseMove(element(by.css('.popover')).find()).perform();
     expect(element(by.css('.popover-content'))
     .isDisplayed().toBeTruthy());
 });

テストは実行されているようで、ブラウザは開きますが、ブラウザが閉じる前にポップアップ コンテンツが表示されないので、何らかの理由で mousemove ビットが機能していないと確信しています。次に、ターミナルに次のように出力されます。

launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
ycompu:angular ycompu$  

私はドキュメントを読みましたが、ブラウザを使用することは間違いなくこのテストに取り組む正しい方法です。構文が正しいように見えるので、途方に暮れています。

4

5 に答える 5

2

偶然、クロムでのマウスホバーの問題の回避策を発見しました。mouseMove() メソッドを 2 回チェーンすると、機能します。

クロムで動作しないコード:

browser.actions.mouseMove(element).click().perform();

回避策を含むコード(これは機能します):

browser.actions.mouseMove(element).mouseMove(element).click().perform();
于 2018-11-16T19:46:25.697 に答える
1

角度のないサイトについては、以下のコードを試してください。コードはテストされ、分度器 -- バージョン 5.4.2 で最新の Chrome 79 に合格しました。

describe('My first test class', function() {
    it('My function', function() {
        browser.driver.ignoreSynchronization = true;// for non-angular set true. default value is false 
        browser.waitForAngularEnabled(false);
        browser.driver.get('http://demoqa.com/menu/');
       //var menuElectronics= element(by.id('ui-id-4'));//We can define an element and move  to it 
      //browser.actions().mouseMove(menuElectronics).perform();
      //Directly find the element using id
      browser.actions().mouseMove(element(by.id('ui-id-4'))).perform();
       //Click on the element that appeared after hover over the electronics
       element(by.id('ui-id-7')).click();   
    });

})
于 2019-12-18T04:56:32.617 に答える