-3

please I have problem with equaling object and string, if print each of both (with method sendKeys();), it's has the same value, but this condition is false. When I cast object to string is undefined. The thisAdspaceNumb is from angular table. I want to generate ADSPACEx (like ADSPACE3, ADSPACE4 .... it is unique key). I know, this is one way to get the "id" but I'd prefer substring only the number of key and increment it. Thank you

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<table id="adspaceTable" ng-table="adspaceTable" class="table  ng-scope ng-table" style="table-layout: fixed;"><!-- ngInclude: templates.header --><thead ng-include="templates.header" class="ng-scope"><tr class="ng-scope"> <!-- ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined col-sm-2 ellipsing sortable sort-asc"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope">Code</div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined col-sm-3 ellipsing sortable sort-asc"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope">Name</div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined col-sm-3 ellipsing sortable"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope">Description</div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined  col-sm-2 sortable ng-hide"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope">Expired</div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined col-sm-2 nowrap"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope"> </div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --> </tr> <tr ng-show="show_filter" class="ng-table-filters ng-scope ng-hide"> <!-- ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope ng-hide"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --> </tr></thead>
        <tbody><!-- ngRepeat: adspace in $data --><tr ng-repeat="adspace in $data" ng-click="changeSelection(adspace, selectedAdspace.$edit)" ng-class="{'active': adspace.$selected}" class="ng-scope">
          <td id="TabCode" data-title="translate('win-web-adspace.lbl-code')" class="col-sm-2 ellipsing ng-binding" sortable="'code'" data-title-text=" ">ADSPACE1</td>
          <td data-title="translate('win-web-adspace.lbl-name')" class="col-sm-3 ellipsing ng-binding" sortable="'name'" data-title-text=" ">Ad Space 1</td>
          <td data-title="translate('win-web-adspace.lbl-desc')" class="col-sm-3 ellipsing ng-binding" sortable="'desc'" data-title-text=" ">Ad Space 1</td>
          <td ng-show="expiredFilter == 2" data-title="translate('global.lbl-expired')" class="col-sm-2 ng-hide" sortable="'expired'" data-title-text=" ">
            <input type="checkbox" ng-model="adspace.adspaceExpired" ng-true-value="true" ng-false-value="false" ng-disabled="true" ng-checked="adspace.adspaceExpired" class="ng-pristine ng-valid" disabled="disabled">
          </td>
          <td class="col-sm-2 nowrap" data-title-text=" ">
            <!-- ngIf: !selectedAdspace.$edit --><a ng-if="!selectedAdspace.$edit" class="row-icon ng-scope">
              <i class="fa fa-lg fa-pencil-square-o cursor-pointer"></i>
            </a><!-- end ngIf: !selectedAdspace.$edit -->
            &nbsp;&nbsp;
            <!-- ngIf: !selectedAdspace.$edit && !adspace.expired --><!-- cawAuth: hasRole('ROLE_MC_ADM_OL_ADSPACE_D') --><a ng-really-click="deleteAdspace(adspace);" ng-really-message="This action cannot be undone. Are you sure you want to delete this?" ng-if="!selectedAdspace.$edit &amp;&amp; !adspace.expired" class="row-icon ng-scope ng-isolate-scope" caw-auth="hasRole('ROLE_MC_ADM_OL_ADSPACE_D')">
              <i class="fa fa-lg fa-times cursor-pointer"></i>
            </a><!-- end cawAuth: hasRole('ROLE_MC_ADM_OL_ADSPACE_D') --><!-- end ngIf: !selectedAdspace.$edit && !adspace.expired -->
          </td>
        </tr><!-- end ngRepeat: adspace in $data --><tr ng-repeat="adspace in $data" ng-click="changeSelection(adspace, selectedAdspace.$edit)" ng-class="{'active': adspace.$selected}" class="ng-scope">
          <td id="TabCode" data-title="translate('win-web-adspace.lbl-code')" class="col-sm-2 ellipsing ng-binding" sortable="'code'" data-title-text=" ">ADSPACE2</td>
          <td data-title="translate('win-web-adspace.lbl-name')" class="col-sm-3 ellipsing ng-binding" sortable="'name'" data-title-text=" ">Ad Space 2</td>
          <td data-title="translate('win-web-adspace.lbl-desc')" class="col-sm-3 ellipsing ng-binding" sortable="'desc'" data-title-text=" ">Ad Space 2</td>
          <td ng-show="expiredFilter == 2" data-title="translate('global.lbl-expired')" class="col-sm-2 ng-hide" sortable="'expired'" data-title-text=" ">
            <input type="checkbox" ng-model="adspace.adspaceExpired" ng-true-value="true" ng-false-value="false" ng-disabled="true" ng-checked="adspace.adspaceExpired" class="ng-pristine ng-valid" disabled="disabled">
          </td>
          <td class="col-sm-2 nowrap" data-title-text=" ">
            <!-- ngIf: !selectedAdspace.$edit --><a ng-if="!selectedAdspace.$edit" class="row-icon ng-scope">
              <i class="fa fa-lg fa-pencil-square-o cursor-pointer"></i>
            </a><!-- end ngIf: !selectedAdspace.$edit -->
            &nbsp;&nbsp;
            <!-- ngIf: !selectedAdspace.$edit && !adspace.expired --><!-- cawAuth: hasRole('ROLE_MC_ADM_OL_ADSPACE_D') --><a ng-really-click="deleteAdspace(adspace);" ng-really-message="This action cannot be undone. Are you sure you want to delete this?" ng-if="!selectedAdspace.$edit &amp;&amp; !adspace.expired" class="row-icon ng-scope ng-isolate-scope" caw-auth="hasRole('ROLE_MC_ADM_OL_ADSPACE_D')">
              <i class="fa fa-lg fa-times cursor-pointer"></i>
            </a><!-- end cawAuth: hasRole('ROLE_MC_ADM_OL_ADSPACE_D') --><!-- end ngIf: !selectedAdspace.$edit && !adspace.expired -->
          </td>
        </tr><!-- end ngRepeat: adspace in $data -->
      </tbody></table>
//The thisAdspaceNumb = ADSPACE2;
    var thisAdspaceNumb = "";
    var nextAdspaceNumb;
    thisAdspaceNumb = element.all(by.id('TabCode')).last().getText();//.toString().substring(7,10);
    for(var i = 0;i < 10;i++) 
    {
        var tmp = "ADSPACE" +i;

        if(thisAdspaceNumb == tmp)
        {
            nextAdspaceNumb = "ADSPACE" + (i + 1);
            break;
        }
    }
    element(by.id("code")).sendKeys(nextAdspaceNumb);`
Kex
  • 93
  • 1
  • 9

1 Answers1

0

In thisAdspaceNumb, getText() returns a Promise, so you would need to use it like:

element.all(by.id('TabCode')).last().getText().then(function(text) {
    var thisNumber = parseInt(/(\d+)/.exec(text)[1]);
    return thisNumber + 1;
}).then(function(nextNumber) {
    element(by.id('code')).sendKeys(nextNumber);
});
martin770
  • 1,271
  • 11
  • 15
  • It's working ! Thank you very much, just i have to change index from 1 to 0 (text)[0] – Kex Dec 10 '15 at 05:31
  • Good catch, I forgot to add parentheses for the capture group in the regular expression. I edited to be: /(\d+)/.exec(text)[0] – martin770 Dec 15 '15 at 14:48