在量角器中实现if和else

时间:2016-11-30 12:39:36

标签: selenium if-statement protractor

我有一个这样的场景,当用户选择public没有问题但是当选择一个私有时,这里的模态应该弹出并点击确定。 HTML代码:

<div ng-show="private" class="privateSetting">
      <h5>privacy Settings</h5>
      <div>
          <md-switch ng-model="privacySwitch" style="width:35%;" class="md-primary md-switch" ng-click="privacySettings()">{{displayText}}
          </md-switch>
      </div>
      <p>privacy Msg</p>

    </div>

测试代码:

 element(by.css('aria-label=Private')).isDisplayed().then(function(result)
 {
     if ( result ) {
         element(by.css('[ng-click="privacySettings()"]')).click();
         browser.sleep(5000);
         element(by.className('btn btn-primary')).click();
        browser.sleep(5000);

     } else {

         element(by.css('[ng-click="privacySettings()"]')).click();
        browser.sleep(5000);
    }

1 个答案:

答案 0 :(得分:0)

element(by.model("privacySwitch")).isDisplayed().then(function(Private)
 {
     if ( Private ) {
        element(by.css('[ng-click="privacySettings()"]')).click();
        browser.sleep(5000);
        element(by.css('[ng-click="ok()"]')).click();
        browser.sleep(5000);

     } else {

        element(by.css('[ng-click="privacySettings()"]')).click();
        browser.sleep(5000);
     }

 });