2017-04-05 172 views
0

我想從json讀取數據(2個週期)並添加一個條目。數據第一次成功添加,但在第二個週期中失敗。以下是詳細信息。與頁面對象一起運行並且不從json讀取時也工作;不讀取json的第二個數據

「test_pom_fromjson」已成功添加,但運行test_pom_fromjson_first時失敗,錯誤顯示沒有找到使用element(by.id('s2id_autogen10')).click();的元素,它是位置列的定位器。

參考截圖和HTML代碼的頁面 - https://pastebin.com/ZXyRx1tv add page

mo.ts: pageobject for the below spec file 
 

 
    var mo = function() { 
 
this.createbutton = function() { 
 
     var createb = element(by.css('button[title="Add Master Obligation"]')) 
 
     //var createbutton = element(by.buttonText('↵ ↵ Add Master Obligatio...↵ ')) 
 
     browser.executeScript("arguments[0].scrollIntoView();arguments[1].click();", createb, createb); 
 

 

 
    } 
 

 

 
    this.MasterObligationName = function (value) { 
 

 

 
     element(by.model('obligation.ObligationName')).sendKeys(value); 
 
    } 
 

 
    this.Module = function (value) { 
 

 

 
     element(by.id('s2id_TaxProcess')).click(); 
 
     element.all(by.repeater('item in obligation.TaxProcess.list')).get(value).click(); 
 
    } 
 

 
    this.Location = function (value) { 
 

 

 
     element(by.id('s2id_autogen10')).click(); 
 
     element.all(by.repeater('item in obligation.Jurisdiction.list')).get(value).click(); 
 
    } 
 

 
    this.CentralObligation = function (value) { 
 

 

 
     element.all(by.model('obligation.CentralObligation')).get(value).click(); 
 
    } 
 
    this.Type = function (value) { 
 

 

 
     element(by.id('s2id_txtReturnType')).click(); 
 
     element.all(by.repeater('item in obligation.ReturnType.list')).get(value).click(); 
 
    } 
 
    this.Years = function (value) { 
 

 

 
     element(by.id('s2id_txtTaxYear')).click(); 
 
     element.all(by.repeater('item in obligation.TaxYears.list')).get(value).click(); 
 
    } 
 
    this.Periods = function (value) { 
 

 

 
     element(by.id('s2id_txtPeriod')).click(); 
 
     element.all(by.repeater('tem in obligation.Periods.list')).get(value).click(); 
 
    } 
 
    this.Forms = function (value) { 
 

 

 
     element.all(by.id('s2id_txtForms')).get(0).click(); 
 
     element.all(by.repeater('item in obligation.Forms.list')).get(value).click(); 
 
    } 
 
    this.Reports = function (value) { 
 

 

 
     element.all(by.id('s2id_txtForms')).get(1).click(); 
 
     element.all(by.repeater('item in obligation.Reports.list')).get(value).click(); 
 
    } 
 

 
    this.savebutton = function() { 
 

 

 
     var saveb = element(by.css('button[title="Save"]')) 
 
     browser.executeScript("arguments[0].scrollIntoView();arguments[1].click();", saveb, saveb); 
 

 

 
    } 
 

 
    module.exports = new mo();


          
  
spec.ts:                   var mo = require("../page/mo.ts") 
 
    var testData = require('../testdata/testdata.json'); 
 

 
    testData.forEach(function (data) { 
 
     it('create and save master obligation', function() { 
 
      browser.sleep(10000); 
 
      mo.createbutton(); 
 
      browser.sleep(10000); 
 
      mo.MasterObligationName(data.Master_Obligation_Name) 
 
      mo.Module(data.Module); 
 
      mo.Location(data.Location); 
 
      mo.CentralObligation(data.Central_Obligation); 
 
      mo.Type(data.Type); 
 
      mo.Years(data.Years); 
 
      mo.Periods(data.Periods); 
 
      mo.Forms(data.Forms); 
 
      mo.Reports(data.Reports); 
 
      mo.savebutton(); 
 
     }) 
 

 
    })
testdata.json: [{ "Master_Obligation_Name": "test_pom_fromjson", "Module": "2", "Location": "1", "Central_Obligation": "0", "Type": "2", "Years": "1", "Periods": "1", "Forms": "1", "Reports": "0" }, { "Master_Obligation_Name": "test_pom_fromjson_first", "Module": "2", "Location": "1", "Central_Obligation": "0", "Type": "2", "Years": "1", "Periods": "1", "Forms": "1", "Reports": "0" }]
+0

我只是想知道,它失敗的地方?第二次添加主要責任,頁面是否出現,錯誤發生或主頁義務頁面丟失? –

+0

嗨@KishanPatel早上好。感謝您花費寶貴的時間來研究這個問題。它失敗,錯誤說沒有使用元素找到元素(by.id('s2id_autogen10'))。click();這是位置列的定位器。所以我不確定它是如何發現的第一次,並在第二個或第三個 – kavitha

+1

2選項中失敗,你可以嘗試: 1.等待一段時間之前,點擊 2.任何一個id號是自動生成的,所以它可能會改變每次都使用其他定位器。 –

回答

1

兩個選項,你可以嘗試:

1.Wait了前一段時間那點擊

2.任何一個id號碼都是自動生成的,所以可能會每次都更改,所以請使用其他定位器。

如果ID是自動生成的,然後尋找和其它一些定位:

element.all(by.id('s2id_Jurisdiction')).get(1).click(); 
element.all(by.repeater('item in obligation.Jurisdiction.list')).get(value).click(); 

,或者您也可以嘗試以下方式:

var module = element(by.xpath("//input[starts-with(@id, 's2id_autogen')]")).get(1).click(); 

var location= element(by.xpath("//input[starts-with(@id, 's2id_autogen')]")).get(2).click(); 

var type = element(by.xpath("//input[starts-with(@id, 's2id_autogen')]")).get(3).click(); 
相關問題