简体   繁体   中英

element.getText().then(function) not being executed

I am working with protractor and cucumber . I want to print the text returned from getText. I am using .then function to obtain such text, but for some reason, console.log code is not being executed.

Why is this happening?

checkDropdown: function (value, dropdown) {
    let name = element(by.id(dropdown));
    name.getText().then(function(text){
        console.log(text);
    });
    expect(name.getText()).to.eventually.equal(value);
},

The protractor.conf.js file is: Protractor file is:

exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub', // This is targetting your local running instance of the selenium webdriver

specs: [
    '../Features/UI_Tests.feature'
],

capabilities: {
    browserName: 'chrome' // You can use any browser you want. On a CI environment you're going to want to use PhantomJS
},

framework: 'custom', //We need this line to use the cucumber framework

frameworkPath: require.resolve('protractor-cucumber-framework'), // Here it is

cucumberOpts: {
    //format:  'pretty',
    require: '../Features/step_definitions/my_steps.js', // This is where we'll be writing our actual tests
    //tags: ['@login','@app'],
    strict: true,
    plugin:"json"
},
resultJsonOutputFile:'./testResults.json', //output file path to store the final results in .json format
params: {
    env: {
        hostname: 'http://0.0.0.0:8000' // Whatever the address of your app is
    }
}
};

Thanks in advance.

May be the text value which you log is blank.

Can you try adding some test in front of your text

 name.getText().then((text)=>{
        console.log('Text value is' + text);
 });

Just to check if console.log is executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM