下面显示的页面由包含患者列表的表格图像组成。我想写一个e2e测试,但这是我的新手。
给定下面显示表项的代码,如何访问表中的项并通过检查行和列以及检查数据是否存在来对其进行测试?
<table _ngcontent-c34="" class="col-md-12 mat-table" mat-table="" matsort="" role="grid" ng-reflect-data-source="[object Object]">
<thead>
<!---->
<tr _ngcontent-c34="" class="mat-header-row ng-star-inserted" mat-header-row="" role="row">
<!---->
<th _ngcontent-c34="" class="mat-header-cell ng-tns-c36-43 cdk-column-patientName mat-column-patientName ng-star-inserted" mat-header-cell="" mat-sort-header="patientName" mattooltip="Sort by pa tient name" role="columnheader" aria-describedby="cdk-describedby-message-17" cdk-describedby-host="" ng-reflect-message="Sort by pa tient name" ng-reflect-id="patientName">
<div class="mat-sort-header-container">
<button class="mat-sort-header-button" type="button" aria-label="Change sorting for patientName">Patient</button>
<div class="mat-sort-header-arrow ng-trigger ng-trigger-arrowPosition" style="transform: translateY(25%); opacity: 0;">
<div class="mat-sort-header-stem"></div>
<div class="mat-sort-header-indicator ng-trigger ng-trigger-indicator" style="transform: translateY(0px);">
<div class="mat-sort-header-pointer-left ng-trigger ng-trigger-leftPointer" style="transform: rotate(-45deg);"></div>
<div class="mat-sort-header-pointer-right ng-trigger ng-trigger-rightPointer" style="transform: rotate(45deg);"></div>
<div class="mat-sort-header-pointer-middle"></div>
</div>
</div>
</div>
</th>
<!---->
<th _ngcontent-c34="" class="mat-header-cell ng-tns-c36-44 cdk-column-age mat-column-age ng-star-inserted" mat-header-cell="" mat-sort-header="age" mattooltip="Patient Age" role="columnheader" aria-describedby="cdk-describedby-message-18" cdk-describedby-host="" ng-reflect-message="Patient Age" ng-reflect-id="age">
<div class="mat-sort-header-container">
<button class="mat-sort-header-button" type="button" aria-label="Change sorting for age">Age</button>
<div class="mat-sort-header-arrow ng-trigger ng-trigger-arrowPosition" style="transform: translateY(25%); opacity: 0;">
<div class="mat-sort-header-stem"></div>
<div class="mat-sort-header-indicator ng-trigger ng-trigger-indicator" style="transform: translateY(0px);">
<div class="mat-sort-header-pointer-left ng-trigger ng-trigger-leftPointer" style="transform: rotate(-45deg);"></div>
<div class="mat-sort-header-pointer-right ng-trigger ng-trigger-rightPointer" style="transform: rotate(45deg);"></div>
<div class="mat-sort-header-pointer-middle"></div>
</div>
</div>
</div>
</th>
<!---->
<th _ngcontent-c34="" class="mat-header-cell ng-tns-c36-45 cdk-column-birth mat-column-birth ng-star-inserted" mat-header-cell="" mat-sort-header="birth" mattooltip="Patient Birth Date" role="columnheader" aria-describedby="cdk-describedby-message-19" cdk-describedby-host="" ng-reflect-message="Patient Birth Date" ng-reflect-id="birth">
<div class="mat-sort-header-container">
<button class="mat-sort-header-button" type="button" aria-label="Change sorting for birth"> Birth</button>
<div class="mat-sort-header-arrow ng-trigger ng-trigger-arrowPosition" style="transform: translateY(25%); opacity: 0;">
<div class="mat-sort-header-stem"></div>
<div class="mat-sort-header-indicator ng-trigger ng-trigger-indicator" style="transform: translateY(0px);">
<div class="mat-sort-header-pointer-left ng-trigger ng-trigger-leftPointer" style="transform: rotate(-45deg);"></div>
<div class="mat-sort-header-pointer-right ng-trigger ng-trigger-rightPointer" style="transform: rotate(45deg);"></div>
<div class="mat-sort-header-pointer-middle"></div>
</div>
</div>
</div>
</th>
<!---->
<th _ngcontent-c34="" class="mat-header-cell ng-tns-c36-46 cdk-column-sex mat-column-sex ng-star-inserted" mat-header-cell="" mat-sort-header="sex" mattooltip="Patient Gender" role="columnheader" aria-describedby="cdk-describedby-message-20" cdk-describedby-host="" ng-reflect-message="Patient Gender" ng-reflect-id="sex">
<div class="mat-sort-header-container">
<button class="mat-sort-header-button" type="button" aria-label="Change sorting for sex">Sex</button>
<div class="mat-sort-header-arrow ng-trigger ng-trigger-arrowPosition" style="transform: translateY(25%); opacity: 0;">
<div class="mat-sort-header-stem"></div>
<div class="mat-sort-header-indicator ng-trigger ng-trigger-indicator" style="transform: translateY(0px);">
<div class="mat-sort-header-pointer-left ng-trigger ng-trigger-leftPointer" style="transform: rotate(-45deg);"></div>
<div class="mat-sort-header-pointer-right ng-trigger ng-trigger-rightPointer" style="transform: rotate(45deg);"></div>
<div class="mat-sort-header-pointer-middle"></div>
</div>
</div>
</div>
</th>
<!---->
<th _ngcontent-c34="" class="mat-header-cell ng-tns-c36-47 cdk-column-location mat-column-location ng-star-inserted" mat-header-cell="" mat-sort-header="location" mattooltip="Patients Location" role="columnheader" aria-describedby="cdk-describedby-message-21" cdk-describedby-host="" ng-reflect-message="Patients Location" ng-reflect-id="location">
<div class="mat-sort-header-container">
<button class="mat-sort-header-button" type="button" aria-label="Change sorting for location">Location</button>
<div class="mat-sort-header-arrow ng-trigger ng-trigger-arrowPosition" style="transform: translateY(25%); opacity: 0;">
<div class="mat-sort-header-stem"></div>
<div class="mat-sort-header-indicator ng-trigger ng-trigger-indicator" style="transform: translateY(0px);">
<div class="mat-sort-header-pointer-left ng-trigger ng-trigger-leftPointer" style="transform: rotate(-45deg);"></div>
<div class="mat-sort-header-pointer-right ng-trigger ng-trigger-rightPointer" style="transform: rotate(45deg);"></div>
<div class="mat-sort-header-pointer-middle"></div>
</div>
</div>
</div>
</th>
<!---->
<th _ngcontent-c34="" class="mat-header-cell ng-tns-c36-48 cdk-column-phone mat-column-phone ng-star-inserted" mat-header-cell="" mat-sort-header="phone" mattooltip="Patient's phone number" role="columnheader" aria-describedby="cdk-describedby-message-22" cdk-describedby-host="" ng-reflect-message="Patient's phone number" ng-reflect-id="phone">
<div class="mat-sort-header-container">
<button class="mat-sort-header-button" type="button" aria-label="Change sorting for phone"> Phone</button>
<div class="mat-sort-header-arrow ng-trigger ng-trigger-arrowPosition" style="transform: translateY(25%); opacity: 0;">
<div class="mat-sort-header-stem"></div>
<div class="mat-sort-header-indicator ng-trigger ng-trigger-indicator" style="transform: translateY(0px);">
<div class="mat-sort-header-pointer-left ng-trigger ng-trigger-leftPointer" style="transform: rotate(-45deg);"></div>
<div class="mat-sort-header-pointer-right ng-trigger ng-trigger-rightPointer" style="transform: rotate(45deg);"></div>
<div class="mat-sort-header-pointer-middle"></div>
</div>
</div>
</div>
</th>
<!---->
<th _ngcontent-c34="" class="mat-header-cell ng-tns-c36-49 cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-header-cell="" mat-sort-header="lVisit" mattooltip="Patients Last Visit" role="columnheader" aria-describedby="cdk-describedby-message-23" cdk-describedby-host="" ng-reflect-message="Patients Last Visit" ng-reflect-id="lVisit">
<div class="mat-sort-header-container">
<button class="mat-sort-header-button" type="button" aria-label="Change sorting for lVisit">Last Visit</button>
<div class="mat-sort-header-arrow ng-trigger ng-trigger-arrowPosition" style="transform: translateY(25%); opacity: 0;">
<div class="mat-sort-header-stem"></div>
<div class="mat-sort-header-indicator ng-trigger ng-trigger-indicator" style="transform: translateY(0px);">
<div class="mat-sort-header-pointer-left ng-trigger ng-trigger-leftPointer" style="transform: rotate(-45deg);"></div>
<div class="mat-sort-header-pointer-right ng-trigger ng-trigger-rightPointer" style="transform: rotate(45deg);"></div>
<div class="mat-sort-header-pointer-middle"></div>
</div>
</div>
</div>
</th>
<!---->
</tr>
</thead>
<tbody>
<!---->
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">Alextest Ktest</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">36</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> 06/07/1983 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell">Male</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">Test, Test</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> 123 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">No Record Yet</td>
</tr>
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">Another Name Name Last</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">0</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> 06/09/2019 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell">Male</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">Kenya, Kenya</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> 0748828422 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">No Record Yet</td>
</tr>
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">AnotherName2 LasName2</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">0</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> 06/13/2019 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell">Male</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">Kenya, Kenya</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> 35234234234 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">No Record Yet</td>
</tr>
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">John Doe</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">29</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> 06/13/1990 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell">Male</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">Kenya, Nairobi</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> 1234567 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">06/10/2019</td>
</tr>
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">Lilo wanjiru</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">No Record</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> Invalid date </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell"></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">, </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">No Record Yet</td>
</tr>
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">dfds ffdgdfg</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">0</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> 06/14/2019 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell">Male</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">Kenya, Nairobi</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> 5129862770 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">No Record Yet</td>
</tr>
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">dfds ffdgdfg</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">No Record</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> Invalid date </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell"></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">, </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">No Record Yet</td>
</tr>
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">dfds ffdgdfg</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">No Record</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> Invalid date </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell"></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">, </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">No Record Yet</td>
</tr>
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">dfds ffdgdfg</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">No Record</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> Invalid date </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell"></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">, </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">No Record Yet</td>
</tr>
<tr _ngcontent-c34="" class="mat-row ng-star-inserted" mat-row="" role="row">
<!---->
<td _ngcontent-c34="" class="mat-cell cdk-column-patientName mat-column-patientName ng-star-inserted" mat-cell="" role="gridcell"><a _ngcontent-c34="" class="patient-name">dsfsdf dfsfsd</a></td>
<td _ngcontent-c34="" class="mat-cell cdk-column-age mat-column-age ng-star-inserted" mat-cell="" role="gridcell">0</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-birth mat-column-birth ng-star-inserted" mat-cell="" role="gridcell"> 06/20/2019 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-sex mat-column-sex ng-star-inserted" mat-cell="" role="gridcell">Male</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-location mat-column-location ng-star-inserted" mat-cell="" role="gridcell">Kenya, Nairobi</td>
<td _ngcontent-c34="" class="mat-cell cdk-column-phone mat-column-phone ng-star-inserted" mat-cell="" role="gridcell"> 0792345678 </td>
<td _ngcontent-c34="" class="mat-cell cdk-column-lVisit mat-column-lVisit ng-star-inserted" mat-cell="" role="gridcell">No Record Yet</td>
</tr>
</tbody>
<tfoot class="mat-table-sticky" style="bottom: 0px; position: sticky; z-index: 10;">
<!---->
</tfoot>
</table>
答案 0 :(得分:0)
您应该查看角度js locators和repeaters。定位器将帮助您通过id,className,name,CSS等定位元素,然后在使用中继器生成表的情况下,只需编写一个循环即可获取表中存在的行和列并检查它们是否包含数据。
有关更多信息,请参见Protractor API