Nightwatch Unable to locate element using xpath - nightwatch.js

I am new to Nightwatch and trying to write a simple test. I am getting the following error.
ERROR: Unable to locate element: "//label[data-id="CC"]" using: xpath
let suite = {
"Test 1.": function (client) {
client.useXpath();
page = client.page.configure.deviceProperties.default();
page.navigate();
page.waitForLoader();
},
"column selector": function(client){
page
.verify.containsText('//label[data-id="CC"]', 'CC')
client.pause(100);
}
I also have tried with
'label[data-id="CC"]'
'label[#data-id="CC"]'
What am I doing wrong? Thanks in advance.
-dj

the attribute must contains prefix # using xpath (as you have specified)
like "//label[#data-id='CC']" which should works
and in CSS it looks like "label[data-id='CC']"
add a waiting step before test like waitForElement
[using xpath]
page.waitForElementVisible("//label[#data-id='CC']", 2000, false, function(result){
if (result.status === 0) {
page.verify.containsText("//label[#data-id='CC']", 'CC')
}
});
or expect :
page.expect.element("//label[#data-id='CC']").text.to.contain('CC').before(2000);

use ('//label[#data-id="CC"]', 'CC'), and you should try your xpath in the browser console to test whether the xpath is correct or not.

Related

cy.url().should() failing with type error

We have the following piece of code that fails intermittently.
cy.url().then((url) => {
if (url.includes('https://app') || url.includes('https://auth')) {
cy.url().should('match', /\/agent|\/worker/, { timeout: 30000 }) ^
}
})
The failure happens in the second cy.url() command where the should match condition fails with the error "[object Object]: expected undefined to match". We only see this error every once or so in 10 time.
Instead of again using cy.url(), use the previous url you extracted with cy.wrap(), something like this:
cy.url().then((url) => {
if (url.includes('https://app') || url.includes('https://auth')) {
cy.wrap(url).should('match', /\/agent|\/worker/, {timeout: 30000})
}
})
I'm not sure of the reason for covering multiple scenarios like this would be.
Also, you don't give an example of the url, I'm going to assume your regex is to check the pathname of the url.
cy.location('pathname').should('match', /\/agent|\/worker/i)

How to verify a failed scenario in After method i'm using Nightwatch API (formerly Night-Cucumber). To Update browserstack rest API (pass/fail)

I am using Nightwatch API(formerly Nightwatch-Cucumber) in browserstack. I am unable to find a code to update the status of Rest Api (passed/failed) in browserstack by verifying failed scenarios in my test. I need to use this in my After method.
thanks in advance.
I wanted to use similar one as below code in Cucumber.conf.js file
afterTest: test => {
if (!test.passed) {
request({uri: https://${user}:${key}#api.browserstack.com/app- automate/sessions/${browser.sessionId}.json,
method:'PUT',
form:{ 'status':'error','reason': errors.join(' | ') },
})
}
You should have below library in the script:
var request = require("request");
You can use the following code:
request({uri: "https://:#api.browserstack.com/automate/sessions/.json", method:"PUT", form:{"status":"passed","reason":""}})
You can refer the sample code from the below link:
https://www.browserstack.com/automate/node#rest-api

WebdriverIO waitUntil example is not working

I am trying to use Webdriverio v5 and I have problems to run the example for waitUntil https://webdriver.io/docs/api/browser/waitUntil.html
it('should wait until text has changed', () => {
browser.waitUntil(() => {
return $('#someText').getText() === 'I am now different'
}, 5000, 'expected text to be different after 5s');
});
the error is saying
Type 'boolean' is not assignable to type 'Promise<boolean>'
anyone else is facing the same problem?
or how to fix it?
while in v4 everything works as expected
It looks like you're using typescript in your tests. Make sure you've gone through the entire typescript/webdriverio setup: https://webdriver.io/docs/typescript.html
In this case, I think you need to add wdio-sync to your compilerOptions types setting.
"compilerOptions": {
"types": ["node", "#wdio/sync"]
}

Is there a way to add cypress test steps execution information into allure report?

I'm trying to add test step information into an allure report, i use cypress and generate report with allure, report are correctly generate but no details appears in testcases.
I try to use the on('task') without success...
my plugins/index.js contain:
...
on('task', {
allureTestStep () {
const testStep = allure.createStep("Initial", () => {
console.log("First Test")
});
testStep()
return null
}
})
...
and i call it with:
cy.task('allureTestStep')
in my test.
No log in console only two error:
allure-js-commons: Unexpected startStep() of initial. There is no parent step
First Test
allure-js-commons: Unexpected endStep(). There are no any steps running
and in the report nothing is displayed(no error, no step detail).
Any help is welcome :)
I'm using the cypress-allure plugin and you can set it to show cypress commands in the test results. If you call cy.log those also get placed there. It's pretty nice.
it(`Should have title of ${treeListTitle}`, () => {
cy.log('title should be set');
...
}
Notice in the allure results where that is printed out.

Using user preferences in Firefox addon

I'm building a Firefox Extension. It's injecting CSS into one website. But I want to inject it accordingly to user preferences. This is the most important part in my add-on:
exports.main = function() {
var pageMod = require("page-mod");
var test = require("preferences-service");
pageMod.PageMod({
include: "http://example.org/*",
contentStyle: "something here"
});
};
But there's an error in Mozilla Firefox Error Console:
Error: Module: undefined located at undefined has no authority to load: preferences-service
And I don't know what I should do to make it work. Has anybody any ideas? :) Maybe there's other way?
Actually, I want to read preferences, and then generate adequate styles. I've got user preferences in defaults/preferences/prefs.js, if this is useful information.
Okay, now it works. If you've got the same or similar problem, edit harness-options.json file. After
"page-mod": {
"path": "addon-kit/lib/page-mod.js"
},
add:
"preferences-service": {
"path": "api-utils/lib/preferences-service.js"
}, /*with or without the comma, as the case may */
That's all :)

Resources