如何在量角器中使要在其他测试规格文件中使用的字段详细化

问题描述 投票:0回答:1

我已经在Protractor中的页面对象文件之一中编写了以下函数。

  case 'History':
                          console.log('To do for History');
                          this.artifactsHistory.getText().then((text)=>{
                           console.log(text)
                           this.historyMessage = text
                           console.log('this.historyMessage is '+this.historyMessage)
                          })

这里,我想在字段/变量之一中获取文本,并在spec文件中使用相同的文本。我正在尝试使用'this.historyMessage = text',但是在spec文件中使用相同内容时,什么也不会打印。您能帮我解决这个问题。

node.js jasmine protractor
1个回答
0
投票
import { AppPage } from './app.po';
import { browser, logging, element,by } from 'protractor';

describe('workspace-project App', () => {
  let page: AppPage;
  let title;
  beforeEach(() => {
    page = new AppPage();
  });

  it('should display welcome message', async() => {
    page.navigateTo();
    title =  await page.getTitleText();
    console.log(title)
    expect(page.getTitleText()).toEqual('scriptless app is running!');
  });

  it('print the global title variable',()=>{
    console.log(title) 
  })

  afterEach(async () => {
    // Assert that there are no errors emitted from the browser
    const logs = await browser.manage().logs().get(logging.Type.BROWSER);
    expect(logs).not.toContain(jasmine.objectContaining({
      level: logging.Level.SEVERE,
    } as logging.Entry));
  });
});

声明一个全局范围的变量。在一个it()中为其分配值,然后在另一个中使用它。

您的console.log(text)打印了什么?

© www.soinside.com 2019 - 2024. All rights reserved.