简体   繁体   中英

How to test asp.net webforms(non angular) using Protractor?

I am very new to protractor, and testing .NET Applications. I am trying to build an automation testing script from scratch. Below is the HTML:

<div class = "top">
<span id = "welcome">
<em>Hi</em> 
"," 
<strong>
<span id = "user">MyName</span></strong> 
"|"
</span>'

My protractor code is:

var greet = element(by.id('user')); expect(greet.getText()).toBe('MyName');

I have already done this code:

var greet = element(by.id('welcome')).element(by.id('user'));
expect(greet.getText()).toBe('Hi, MyName'); // or toEqual("Hi, MyName");

But I am still getting an error message saying

Failed: No element found using locator: by.id("welcome")

or

Failed: No element found using locator: by.id("user")

Hoping to hear from all of the experienced protractor testers.

It really looks like a timing issue. Let's try to wait for the element to become present :

var EC = protractor.ExpectedConditions;
var greet = element(by.id('user'));

browser.wait(EC.presenceOf(greet), 5000);

expect(greet.getText()).toBe('MyName');

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