I'm using playwright to do e2e testing to check if the email is exists or not, and while I run my tests its said :
"Finished test flow with status passed"
But its show me that the test is failed because i have assertion error and not because i do something wrong
this is a piece my code:
const fillEmail = async (page: Page, value: string) =>
await page.fill("email-for-test", value);
const fillPassword = async (page: Page, value: string) =>
await page.fill("password-for-test", value);
await fillName(page, name);
await fillEmail(page, email);
const res = await page.locator('.email-error').innerText(); // return error string
expect(res).toContain("Email is already in used");
and i got error, you can see in the picture that I uploaded
any idea how to remove or fix this error
You code actually works. You can also use page.textContent()
const res = await page.locator('.email-error').innerText();
expect(res).toContain("Email is already in use");
const text = await page.textContent('.email-error');
expect(text).toContain("Email is already in use");
How about you just use this:
await expect(page.locator('.email-error')).toContainText(
'Email is already in used',
{timeout: 7000}
)
Also Check if the last word of the assertion message is used or use.
You can also use the text selector and assert it to be visible. Something like this:
await expect(page.locator('text=Email is already in use')).toBeVisible({
timeout: 7000,
})
i soulve this one by upgrade playwright library,
From v1.15 to v1.25
Related
I'm using WebdrivreIO(v7) but unable to export $$ value from another file. If I'm working with the same file it's working fine, but another file not working. not sure what's wrong here
sample.js
module.exports = {
details: $$('.agent-rows p.name'),
}
script_file.js
When("Getting the list from the listing page"){
const sample=require("./sample.js");
console.log("value 1"+ await sample.details) // Output : nothing empty
console.log("value 2"+ await sample.details[0]) // Output : undefined
}
are you sure you are not doing any thing between constant sample, console.log lines? require will trigger the details property as soon as you call it .
so if you are trying the below thing , it won't work
const elem = sample.details
//do something for the element to be present
(await elem)[0].dosomething
because sample.details will trigger the fetch process before the element is present. await is used to wait for an async process to complete, not to trigger it.
use instead:
module.exports = {
details: ()=>{$$('.agent-rows p.name')},
}
in code:
const elem = sample.details
//do something for the element to be present
(await elem())[0].dosomething //here you are triggering the fetch
It seems you have a typo s. It should be sample.detail not sample.details.
When("Getting the list from the listing page"){
const sample=require("./sample.js");
console.log("value 1"+ await sample.detail) // 'detail' not 'details'
}
Let's say I have this in a test:
await t.expect(Selector('input')).ok()
And I would like to have (something like) this:
let func = 'ok';
await t.expect(Selector('input'))[func]()
This is so that I can have a map from selector to function, in order to iterate
over it and check whether some elements are in the page (ok) and some not (notOk).
My above attempt does not work and returns with an interesting error:
code: 'E1035',
data: [
'SyntaxError: test.js: await is a reserved word (325:14)'
]
I believe this is because Testcafe is doing some magic under the hood.
What would be the correct syntax to make it work?
It seems that you skipped the Selector property that you want to check (e.g. exists, visible, textContent, etc.). The following test example works properly with TestCafe v1.14.2:
import { Selector } from 'testcafe';
fixture`A set of examples that illustrate how to use TestCafe API`
.page`http://devexpress.github.io/testcafe/example/`;
const developerName = Selector('#developer-name');
const submitButton = Selector('#submit-button');
test('New Test', async t => {
await t
.typeText(developerName, 'Peter Parker')
.click(submitButton);
let assertFunc = 'ok';
await t.expect(Selector('#article-header').exists)[assertFunc]();
});
await page.isElementVisible('iframe');
console.log('iframe is ready. Loading iframe content');
const elementHandle = await page.waitForSelector("iframe[id='payment-form']");
const frame = await elementHandle.contentFrame();
its working till this point
// console.log('filling form in iframe');
const cardType = await frame.$x(`//div[contains(#class, 'css-12kbcej')]//select[#data-elid="card-type"]`);
await page.click();
also try to do this one as well
await page.waitForXPathAndClick(`//div[contains(#class, 'css-12kbcej')]//select[#data-elid="card-type"]`);
and this as well
const cardType = await frame.$x(`//div[contains(#class, 'css-12kbcej')]//select[#data-elid="card-type"]`);
await frame.click(cardType);
But nothing works out
Error Message
Error: Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': The provided selector is empty.
at puppeteer_evaluation_script:1:33
You have await page.click(); -- page.click() requires a selector, eg page.click('myCssSelector'). That's why you're getting that error, The provided selector is empty
I am using Protractor for e2e testing. The tests should first enter too short username and passwords and because of Angular validators when clicked on a submit button (which is disabled) get rejected and stay put (this works!), then it should enter an username of correct length with also a password of a correct length, click on the submit button and NOT get redirected, because it's a false login. This fails... The last test requires to input correct login details and click on submit and should get redirected to the dashboard.
According to this answer https://stackoverflow.com/a/21785088/12360035 is all it would take to solve my problem that seems to throw the
- Failed: script timeout
(Session info: chrome=79.0.3945.130)
(Driver info: chromedriver=79.0.3945.16 (93fcc21110c10dbbd49bbff8f472335360e31d05-refs/branch-heads/3945#{#262}),platform=Windows NT 10.0.18362 x86_64)```
error for both of my tests.
How do I fix this?
My tests are written this way:
it('should enter too short username and password and NOT get redirected => stay put', () => {
element(by.css('#inputUser')).sendKeys('bah');
element(by.css('#inputPassword')).sendKeys('bah');
const btn = element(by.css('#loginSubmit'));
btn.click();
const curUrl = browser.getCurrentUrl();
expect(curUrl).toBe('http://localhost:4200/avior/login');
});
it('should enter incorrect username and password and NOT get redirected => stay put', () => {
const ele1 = element(by.css('#inputUser'));
const ele2 = element(by.css('#inputPassword'));
const btn = element(by.css('#loginSubmit'));
ele1.clear();
ele2.clear();
ele1.sendKeys('bah');
ele2.sendKeys('bahbahbah');
btn.click();
browser.waitForAngular();
const curUrl = browser.getCurrentUrl();
expect(curUrl).toBe('http://localhost:4200/avior/login');
});
it('should enter correct username and password and get redirected to /avior/dashboard', () => {
const ele1 = element(by.css('#inputUser'));
const ele2 = element(by.css('#inputPassword'));
const btn = element(by.css('#loginSubmit'));
ele1.clear();
ele2.clear();
ele1.sendKeys('Chad');
ele2.sendKeys('chadchad');
btn.click();
browser.waitForAngular();
const curUrl = browser.getCurrentUrl();
expect(curUrl).toBe('http://localhost:4200/avior/dashboard');
});
UPDATE
A jwt token is sent as a cookie in response, that might be part of the problem. I can't seem to find info online on how to handle cookies with Protractor..
Waits in Protractor
Wait for the element to Present
this.waitForElementPresent = function (element) {
return browser.wait(() => (element.isPresent()), 30000);
}
Wait for the element to Display
this.waitForElementDisplayed = function (element) {
return browser.wait(() => (element.isDisplayed()), 30000);
}
Sleep Condition
this.sleep = function (sec) {
browser.sleep(sec * 1000);
}
Expected Conditions
this.waitForElementVisibility = function () {
let EC = ExpectedConditions;
return browser.wait(EC.visibilityOf(), 30000);
}
According to this question Failed: script timeout: result was not received in 11 seconds From: Task: Protractor.waitForAngular() - Locator: By(css selector, #my-btn) adding browser.waitForAngularEnabled(false); before the button clicks seems to have solved the errors..
await browser.wait(function() {
return browser.getCurrentUrl().then(function(url) {
return `cars/detail.aspx${browser.baseUrl}`;
});
}, 5000, "url err");
How do I make protractor wait until cars/detail.aspx${browser.baseUrl} is loaded?
I think you can use the urlContains expected condition in protractor to wait until the url contains something specific. You can refer to the documentation here.
I'm using this method, maybe it will be helpful
export function waitForUrlContains(url: string, customTimeout: number = E2E_TIMEOUT) {
return browser.getCurrentUrl().then(myUrl => {
return browser.wait(protractor.ExpectedConditions.urlContains(url), customTimeout, `URL do not contain: ${url}, and is: ${myUrl}`);
});
}
You can read the Protractor's API documentation for further information on different ways of waiting for an element (url in this case) https://www.protractortest.org/#/api
You have 2 ways actually:
const EC = protractor.ExpectedConditions;
const myUrl = 'cars/detail.aspx${browser.baseUrl}';
then:
return browser.wait(EC.urlIs(myUrl));
OR
return browser.wait(EC.urlContains(myUrl));