菜鸟教程小白 发表于 2022-12-12 17:29:48

iOS:如何断言在 UITest 中选择了一个单元格?


                                            <p><p>我有以下层次结构:
ViewController -> TableView -> TableViewCell -> CollectionView -> CollectionViewCell -> UIImage</p>

<p>tableViewCell上,collectionView里面,有4个cell。每个单元格都有一个唯一的标签。</p>

<p>当用户点击 collectionViewCell 时,单元格会被选中,并且 UIImageView 也会突出显示。在这种情况下,这意味着那里有不同的图像。我启用了 UIImageView 的可访问性并将特征设置为按钮和图像以尝试访问这些 XCUIElementTypes</p>

<p>我无法进行任何 UITest 工作,因为它总是告诉我 UIImageView 有多个结果,即使 ImageView 所在的单元格具有唯一标识符。</p>

<p>如何断言单元格已被选中? </p>

<p>使用我得到的记录功能:
<code>let whatIsYourFilingStatusCellsQuery = XCUIApplication().tables.cells. containsType(.StaticText, identifier:"Single").childrenMatchingType(.Image).matchingIdentifier("btn_unselected").tap()</code></p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>@Che 有正确的想法。</p>

<p>在 <code>didSelectItemAtIndexPath:</code> 中,我这样做了:</p>

<pre><code>cell.accessibilityIdentifier = @&#34;isSelected&#34;;
</code></pre>

<p>然后,在测试文件中:</p>

<pre><code>XCTAssertEqualObjects(randomCellToTap.value, @&#34;isSelected&#34;);
</code></pre>

<p>我还将在 <code>didDeselect...</code></p> 中做相反的事情</p>
                                   
                                                <p style="font-size: 20px;">关于iOS:如何断言在 UITest 中选择了一个单元格?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/34058695/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/34058695/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS:如何断言在 UITest 中选择了一个单元格?