2017-12-29 75 views
0

に動作しません私は分度器スクリプトは、ここで適切に

をやろうとしているまさにである私は、ユーザー

IのgetText(についての情報を含むテーブルでページを開く)要素の数を示しています表中のユーザー(FE「リストで11人のユーザー」)

の私は、「リスト内のユーザー」の部分を削除し、以降のループ

のために、私は、ユーザー名によって特定のユーザーを見つける必要が使用する文字列を整数に変換します(9列目)、j番のwh ichはこのユーザーの情報が入っている行の番号です(これは私が立ち往生した場所です)

私はj行の最初の列に移動します(この特定のユーザーの編集ボタンになります)。私はこれは私が

true 
1 
true 
2 
true 
3 
true 
4 
true 
5 
true 
6 
true 
7 
true 
8 
true 
9 
true 
10 

だから、それは数えるが、常にtrueを返すん得るものです

it("Validation of ND account", function() { 
    //login 
    element(by.id("j_username")).sendKeys($usernameND); 
    element(by.id("j_password")).sendKeys($passwordND); 
    element(by.buttonText("Login")).click(); 
    //navigate to a page with list of users displayed in a table 
    element(by.xpath('//a[@short-title="Users"]')).click(); 
    //narrow the search result by typing 'testuser' 
    element(by.model("userList.searchBox.options.query")).sendKeys($usernameND); 
    //the table has 11 results such as 'testuser', 'testuser1', 'testuser2' 
    //I get text of element with text '11 users in list' to get just the number out of it 
    element(by.xpath('//div[@viewid="userList"]//div[@class="results-count ng-binding"]')).getText().then(function(numberOfUsers) { 
     numberOfUsers = Number(numberOfUsers.replace(" Users in list","")); 
     // declare a variable which will be responsible for accessing to j row in a table 
     var j=1 
     //I search through 11 rows from the table for my username 
     for (i=1; i<numberOfUsers; i++) { 

      element(by.xpath("(//td[@data-field='username'])["+j+"]")).getText().then(function(username){ 

       if (username===$usernameND){ 
        console.log("true"); 
        console.log(j); 
        j++ 
       } else { 
        console.log("false"); 
        j++ 
       } 
      }); 
     } 
    });  
}); 

をしようとしたコードのユーザー

一つの例のユーザー名が異なっていても(最初の行を毎回チェックしているようです)私は今では、各行にアクセスし、罰金のように見えるが、最初の行に、間違って何数11を返す

true 
11 
false 
false 
false 
false 
false 
false 
false 
false 
false 

を取得

element(by.xpath('//div[@viewid="userList"]//div[@class="results-count ng-binding"]')).getText().then(function(numberOfUsers) { 
    numberOfUsers = Number(numberOfUsers.replace(" Users in list","")); 

    for (i=1; i<numberOfUsers; i++) { 
     element(by.xpath("(//td[@data-field='username'])["+i+"]")).getText().then(function(username){ 

      if (username===$usernameND){ 
       console.log("true"); 
       console.log(i); 
      } else { 
       console.log("false"); 
      }  
     });  
    }  
}); 

別のアプローチを試してみてください?それを修正するには?

P.S.私は何をしているのかを例に挙げます screenshot of the page 私のユーザーを見つけてそれに関連する「編集」ボタンをクリックしたいと思います。最初の列の6行目のセルをクリックするだけです。しかし、より多くのユーザーが追加される場合には、信頼できるものにしたいと考えています。これを行うには、ユーザー名列を検索し、このユーザーがテーブル内にある行の番号を文書化し、見つかった行番号の最初の列のセルに移動する必要があります。

答えて

0

私がテーブルの中で探していたユーザーのtrにアクセスしていましたが、この行のボタンの編集をクリックしてください。 2つの例

$username26="testuser26" 
element.all(by.xpath('//trLocator')).first().element(by.xpath("//tr[.//td[@data-field='username' and text()="+$username26+"]]")).element(by.xpath(".//a[text()='Edit']")).click() 

element(by.xpath("//td[@data-field='username' and text()='"+$username26+"']/..")).element(by.xpath(".//a[text()='Edit']")).click(); 

重要な部分は、現在のノードを意味する2番目のxpathのドットです。このドットがないと、文字通りページ上の任意の場所を意味する ".//"は、既に選択した要素から開始することを意味します。

これは長い道ですが、これは私が探していたロジックでした

var tableRows = element.all(by.xpath('xpathTableRowsLocator')); //returns 11 rows 
var mentricsLogo = element(by.css('a.logo')); 
var searchedUsername = "TESTUSER26"; 

//somehow the code didn't work by itself so I had to place it inside of random function whuch I didn't care about 
mentricsLogo.isPresent().then(function(result) { 
     return tableRows.filter(function(eachRow, index) { 
//get text of the whole row and separate it by columns 
      return eachRow.getText().then(function(text){ 
       text=text.split(" ") 
// I get third element is username 
       if (text[2]===searchedUsername){ 
        var xpathIndex = Number(index)+1 
        element(by.xpath("//*[@id='user-list-content']/div[2]/div[2]/div[1]/div[2]/div[1]/table/tbody/tr["+xpathIndex+"]/td[1]/a")).click() 
       } 
      }) 
     }); 
}); 

私はそれが合理的ではないかもしれないが、私のために働いたものは何もわかりません。

0

正直言って、私は何をチェックしていませんでした。

あなたはそれがelementArrayFinderを返す代わりに ​​

element.all(by.xpath("(//td[@data-field='username'])")) を使用することを検討すべきであるまず第一に。 変数(例:tableRows)に割り当てると、それらのデータを処理できます。

あなたは、文字列「リストで11人のユーザー」の数が正しいかどうかを確認しようとしている場合は、ユウは使用することができますtableRows.count()

することもできますfilter要素: http://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.filter

使用maphttp://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.map

正確にテストする必要がある行を削除してください。

編集:

ここにコードサンプルがあります。 定義されたユーザー(この場合はTESTUSER26)のEDITリンクをクリックします。 唯一の変更はdefineSelectorForUsernameCellを実際の値に変更することです。

var tableRows = element.all(by.css('td')); 
var searchedUsername = 'TESTUSER26'; 

return tableRows.filter((eachRow) => { 
    return eachRow.element(by.css('defineSelectorForUsernameCell')).getText((usernameCellText) => { 
     if (usernameCellText === searchedUsername) { 
      return eachRow.element(by.linkText('EDIT')).click(); 
      } 
    }); 
}); 
+0

よく私のテーブルがどれくらいの行を持つかを決定する部分です。はい、それはおそらくあなたのやり方を単純にするでしょうが、これは私が困難に直面しているところではありません。私はP.S.を追加しました。私の質問の段落、私は何をやっている説明を見てみましょう。ありがとうございました –

+0

私の編集 – Kacper

+0

を確認してください。それは私が探しているユーザーの行を見つける(私のテーブルの11の番号6を言うことができます)それは編集ウィンドウを開きますが、その後、そのボタンを5回(11-6)をクリックしようとしますボタンが表示されなくなるため、エラーが発生します。私は –