使用TestCafe Selector或testcafe-react-selector对嵌套组件进行故障查找元素节点

Prr*_*Prr 3 javascript automated-tests reactjs e2e-testing testcafe

我正在使用1.1.0版的TestCafe和3.1.0版的Testcafe-react-selector。我的目标是从节点返回文本。HTML树如下所示:

<div class="header">
     <div class="title">board</div>
     <div class="secondary-title">Wednesday Mar 06, 2019</div>
</div>
<div class="MuiPaper-root-9 MuiPaper-elevation2-02 MuiPaper-rounded-9 board-title-break">
    <div class="board-header">
         <div class="title">Text Title</div>
         <div class="details">
           <div>
               <div>Total</div>
               <div class="header-count total">2 people</div>
           </div>
           <div> ... </div>
           <div> ... </div>
           <div> ... </div>
           ....
           </div>
Run Code Online (Sandbox Code Playgroud)

在这里,我想获取“ 2个人”文本,并验证“ 2个人”是否可见。

我尝试使用Selector,如下所示:

Selector('.header-count total > div')
Run Code Online (Sandbox Code Playgroud)

但这没有解决。

这是从REACT chrome扩展获取的同一HTML树的React Tree:

<TitleBreakdown loading={false} accountId={323}> ==$r
     WithStyles(Paper) className="title-breakdown">
          <Paper className="title-breakdown" component="div" elevation={2} square={false}>
              <div className="MuiPaper-root-9 MuiPaper-elevation2-02 MuiPaper-rounded-9"
                  <div className="board-header">
                      <div class="title">Text Title</div>
                      <div class="details">
                          <div>
                              <div>Total</div>
                              <div class="header-count total">2 people</div>
                          </div>
                          <div> ... </div>
                          <div> ... </div>
                          <div> ... </div>
                           ....
                          </div>
Run Code Online (Sandbox Code Playgroud)

对于上面的React组件,我尝试使用此方法:

ReactSelector('TitleBreakdown').findReact('div').findReact('div').nth(1).findReact('div').nth(1).withKey('header-count total');
Run Code Online (Sandbox Code Playgroud)

总而言之,选择器和ReactSelector都对我不起作用,因为在尝试声明该元素时遇到此错误:

Cannot obtain information about the node because the specified selector does not match any node in the DOM
  tree.
Run Code Online (Sandbox Code Playgroud)

我知道我做错了事,但无法找出问题所在。有人可以告诉您一种处理此类案件的好方法吗?

los*_*mon 8

更改Selector('.header-count total > div')Selector('div.header-count.total')。完整的断言如下所示:

await t
   .expect(Selector('div.header-count.total').innerText).eql('2 people');
Run Code Online (Sandbox Code Playgroud)

我相信它是按照目前的书写方式,告诉TestCafe查找divtotal元素的子元素,total也就是的子元素.header-count。TestCafe认为它正在寻找以下结构:

<div class="header-count">
   <total>
      <div>2 people</div>
   </total>
</div>
Run Code Online (Sandbox Code Playgroud)

查看W3 Schools Selector Reference,以了解每种模式的选择。