2016-06-30 4 views
2

저는 비교를 위해 JSON 데이터를 가져와야하는 각도기 테스트를 수행하고 있습니다. JSONArray의 일부인 콘솔 각도기에서 JSON 데이터 가져 오기

console.log(json.Root.Catalog.ATA_Chapter[index].ATA_Chapter_Title); 

, 그것으로 숫자를 인쇄하고,
"ATA_Chapter": [ 
     { 
      "@id": "01", 
      "ATA_Chapter_Number": "Chapter 01", 
      "ATA_Chapter_Title": "General Airplane Description" 
     }, 
     { 
      "@id": "02", 
      "ATA_Chapter_Number": "Chapter 02", 
      "ATA_Chapter_Title": "Communications" 
     }] 

는 I는 이하의 코드를 사용했는데, 이하

General Airplane Description 
Communications 

를 도시 되나 각도기주고 오류 :

Message: 
    Failed: Cannot read property 'ATA_Chapter_Title' of undefined 

Pls는 위의 기능을 대신하는 방법으로 JSON에 액세스하려고의

var number;var title ; console.log(json.Root.Catalog.ATA_Chapter[index].ATA_Chapter_Title); number = json.Root.Catalog.ATA_Chapter[index].ATA_Chapter_Number; title = json.Root.Catalog.ATA_Chapter[index].ATA_Chapter_Title; var chapterName = number+" "+title; element.all(by.repeater('chapter in chapters')).filter(function (ele,index) { return ele.getText().then(function(text){ console.log('text'+text); return text === chapterName; }); }).click();

+1

사양 파일을 게시 할 수 있습니까? –

+1

코드를 포맷하여이 중 아무것도 만들 수 없습니까? –

+0

질문을 스펙 코드로 업데이트하십시오. 댓글에서 읽을 수 없습니다. – Gunderson

답변

1

를 기록 사양 코드의 부분을 찾아, 난 그렇게처럼 모듈로 치료 및 수출 제안 :

module.exports= { 
    "ATA_Chapter": [ 
     { 
      "@id": "01", 
      "ATA_Chapter_Number": "Chapter 01", 
      "ATA_Chapter_Title": "General Airplane Description" 
     }, 
     { 
      "@id": "02", 
      "ATA_Chapter_Number": "Chapter 02", 
      "ATA_Chapter_Title": "Communications" 
    }] 
} 

그런 다음 당신은 다음처럼 spec 파일에 포함 :

var ataData = require('path/to/your/json/file'); 

var number;var title 

console.log(ataData.ATA_Chapter[index].ATA_Chapter_Title); 

number = ataData.ATA_Chapter[index].ATA_Chapter_Number; 
title = ataData.ATA_Chapter[index].ATA_Chapter_Title; 
var chapterName = number+" "+title; 
element.all(by.repeater('chapter in chapters')).filter(function (ele,index) { 
    return ele.getText().then(function(text){ 
     console.log('text'+text); 
     return text === chapterName; 
    }); 
}).click(); 

이 각도/각도기 디자인 패턴을 조금 내기를 다음과 정의되지 않은 오류에 도움이됩니다. 이 작품이 도움이되는지 알려주세요!