Protractor 从函数内的承诺返回值到测试规范

Protractor 从函数内的承诺返回值到测试规范,protractor,Protractor,我对量角器是新手,我在从角度形式文本字段获取文本值,然后尝试使用该值在同一测试规范中执行后续操作时遇到问题 以下是测试规范代码: it('Demo Test, () => { // Submit the form and get the transaction number var submitButton = element(by.id('submit')); submitButton.click(); // get

我对量角器是新手,我在从角度形式文本字段获取文本值,然后尝试使用该值在同一测试规范中执行后续操作时遇到问题

以下是测试规范代码:

it('Demo Test, () => {

        // Submit the form and get the transaction number
        var submitButton = element(by.id('submit'));
        submitButton.click(); 

        // get the generated transaction number from the screen
        let transactionNum = confirmPage.getTransactionNum();


        // would like to use the transActionNum variable to sendkeys into a 
        // text element
        var searchInput = element(by.id('search'));
        searchInput.sendkeys(transactionNum);                
});
下面是具有函数“getTransactionNum”的类中的一些代码

var transactionNumValue = element(by.id('transactionNumber'));

public getTransactionNum(): any {

    this.transactionNumValue.get().getText().then((transactionValue: string) 
 => {
    return transactionValue;
});
当我运行测试规范并且测试尝试在变量“transactionNum”中键入值时,我得到了“transactionNum未定义”

我希望将事务号作为文本值返回到测试规范,而不是承诺


感谢您的帮助

您错过了
返回
之前的
此操作。transactionNumValue
以及
get()之前的
get()
。getText()
应被删除

var transactionNumValue = element(by.id('transactionNumber'));

public getTransactionNum(): any {

    return this.transactionNumValue.getText()
               .then((transactionValue: string)=>{
                      return transactionValue;
               });
}
在类构造函数中,从量角器为类型
ElementFinder
定义定位器

如果要返回一个元素数组,它可能是
$
元素。所有
都使用来自量角器的type
ElementArrayFinder

var transactionNumValue = element(by.id('transactionNumber'));



public getTransactionNum(): any { return transactionNumValue.getText().then((transactionValue: string) => { return transactionValue; });