Intern/Leadfoot : Getting error - Expecting a function in instanceof check, but got [object Object] on .Click() method - intern

I am learning Intern/leadfoot and trying to write a simple test. The test is logging an user to the site and logging out the user after verification on the next page.
Using Chromedriver v2.21.
Getting unknown error : Expecting a function in instanceof check, but got [object Object] for click() method for an element. However, the element is being identified and get the value for getVisibleText().
Here is my test Code:
define(function (require) {
var registerSuite = require('intern!object');
var assert = require('intern/chai!assert');
registerSuite({
name: 'Acceptance',
'Login': function () {
return this.remote
.get(require.toUrl('http://example.com'))
.setFindTimeout(5000)
.findByXpath('id("ius-userid")')
.click()
.type('user#user.com')
.end()
.findByXpath('id("ius-password")')
.click()
.type('password')
.end()
.findByXpath('id("ius-sign-in-submit-btn")')
.click()
.end()
.sleep(15000)
},
'HomePage': function () {
return this.remote
.setFindTimeout(5000)
.findByXpath('id("userWelcome")')
.getVisibleText()
.then(function (text) {
assert.strictEqual(text, 'Welcome user#user.com!', 'Vaerify that, the Home page for the logged in user is displayed!');
})
.end()
.findByXpath('id("settingsAndLogout")/A[2]')
.getVisibleText()
.then(function(text){
console.log("The Sign out link text is :...", text.trim());
assert.strictEqual(text.trim(), 'Sign Out', 'Verify that, the Sign Out link is present.');
})
.click()
.end()
}
});
});
And, here is the output:
Listening on 0.0.0.0:9000
Tunnel started
? Created session chrome on any platform (5fcd3559690a324e3a5a3db6cd367387)
√ chrome on any platform - Acceptance - Login (20.268s)
The Sign out link text is :... Sign Out
x chrome on any platform - Acceptance - HomePage (0.13s)
UnknownError: [POST http://localhost:4444/wd/hub/session/5fcd3559690a324e3a5a3db
6cd367387/element/0.8815118646376954-2/click] unknown error: Expecting a functio
n in instanceof check, but got [object Object]
(Session info: chrome=49.0.2623.112)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7
c4),platform=Windows NT 6.1 SP1 x86_64)
at runRequest <node_modules\leadfoot\Session.js:88:40>
at <node_modules\leadfoot\Session.js:109:39>
at new Promise <node_modules\dojo\Promise.ts:411:3>
at ProxiedSession._post <node_modules\leadfoot\Session.js:63:10>
at Element._post <node_modules\leadfoot\Element.js:23:31>
at Element.click <node_modules\leadfoot\Element.js:138:15>
at Command.<anonymous> <node_modules\leadfoot\Command.js:680:19>
at <node_modules\dojo\Promise.ts:393:15>
at run <node_modules\dojo\Promise.ts:237:7>
at <node_modules\dojo\nextTick.ts:44:3>
at Command.target.(anonymous function) [as click] <node_modules\leadfoot\Comm
and.js:674:11>
at Test.registerSuite.IQC_HomePage [as test] <tests\functional\IQC_Acceptance
.js:44:7>
at <node_modules\intern\lib\Test.js:181:24>
at <node_modules\intern\browser_modules\dojo\Promise.ts:393:15>
at runCallbacks <node_modules\intern\browser_modules\dojo\Promise.ts:11:11>
at <node_modules\intern\browser_modules\dojo\Promise.ts:317:4>
at run <node_modules\intern\browser_modules\dojo\Promise.ts:237:7>
at <node_modules\intern\browser_modules\dojo\nextTick.ts:44:3>
at nextTickCallbackWith0Args <node.js:453:9>
at process._tickCallback <node.js:382:13>
No unit test coverage for chrome on any platform
Need help in figuring out the issue. Thanks in advance!

Here's a suggestion:
.findByXpath('id("settingsAndLogout")/A[2]')
.getVisibleText()
.then(function(text){
console.log("The Sign out link text is :...", text.trim());
assert.strictEqual(text.trim(), 'Sign Out', 'Verify that, the Sign Out link is present.');
})
.end()
.findByXpath('id("settingsAndLogout")/A[2]')
.click()
.end()
Not the most elegant solution as findbyXpath is redundant. But the thing is, .click() expects that previous command/element promise returns actual element when resolved (findByXpath will do that).
Hope this helps!

Related

Where are playwright screenshots going - and how can I control this?

I have a really basic playwright (v1.18.1) test on Windows (11):
import { test, expect } from '#playwright/test';
test('test', async ({ page }) => {
await page.goto('http://whatsmyuseragent.org/');
//await page.screenshot({ path: `./tests/tmp/screenshots/whats.my.ua.${project:name}.png` });
await page.screenshot();
});
And when I run this - it says it worked
Running : cd C:\playwright\tests && npx playwright test whats_my_user_agent.spec.ts --reporter=list
Running 5 tests using 3 workers
ok [webkit] › whats_my_user_agent.spec.ts:3:1 › test (3s)
ok [firefox] › whats_my_user_agent.spec.ts:3:1 › test (4s)
ok [chromium] › whats_my_user_agent.spec.ts:3:1 › test (5s)
ok [Mobile Chrome] › whats_my_user_agent.spec.ts:3:1 › test (2s)
ok [Mobile Safari] › whats_my_user_agent.spec.ts:3:1 › test (2s)
5 passed (8s)
but I can find no sign of the screenshot file - where are they [there is no feedback giving any hints]. Also - is there a way to control the saved filename (including the project name so that I don't save 5 png files over each other).
As I see it, if you uncomment the line in which you specify the path for your screenshot to be stored, you should find it there, for example, this:
import { test, expect } from '#playwright/test';
test('testing screenshot path', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.screenshot({ path:`./screenshots/screenshot.png` });
});
should result in you having a screenshot of the website named 'screenshot.png' in a folder named 'screenshots' in the root of your project. If there's no folder by that name, it will be created.
As for your question, since this would run the same step (saving a screenshot with a certain name in a certain path) for every project that you're running, your screenshot would be overwritten, leaving you only with the screenshot your last project run. If you'd like all screenshots to be stored, or screenshots for one project in particular (although running several projects), you can play with testInfo. Say you only want to store the screenshots for the project you're running in chromium, though checking the steps pass in every other project; you can do something like this:
test('testing chromium screenshots', async ({ page }, testInfo) => {
await page.goto('https://playwright.dev/');
if (testInfo.project.name === 'chromium') {
await page.screenshot({ path:`./screenshots/${testInfo.title}.png` });
}
});
This would store a screenshot named 'testing chromium screenshots' with the extension .png in the folder 'screenshots' in the root of your project, tested with chromium, while checking the test pass in every other project you might be running.
Hope all this helps.
Ok - I found out how - I needed to include workerInfo in the async declaration, and then I can reference it in the screenshot call:
import { test, expect } from '#playwright/test';
test('test', async ({ page }, workerInfo) => { <----------- added workerInfo
await page.goto('http://whatsmyuseragent.org/');
await page.screenshot({ path: "./tests/tmp/screenshots/whats.my.ua."+workerInfo.project.name+".png" });
// ^^ referenced it with this
});
The screenshot is always returned as a buffer by the screenshot function. If you don't pass a path the only way to get that screenshot is through the buffer.

Unable to use getElementsByTagName("body")

Here's the code that results in an error each time I run it. My goal is to scrap the content from the URL, remove all HTML, and return it:
console.log("Fetching: " + inputData.tweeturl);
fetch(inputData.tweeturl)
.then(function(res) {
return res.text();
}).then(function(body) {
var rawText = body.getElementsByTagName("body")[0].innerHTML;
var output = { id: 100, rawHTML: body, rawText: rawText };
callback(null, output);
})
.catch(callback);
The problem is with var rawText = body.getElementsByTagName("body")[0].innerHTML;
The error I receive is:
Bargle. We hit an error creating a run javascript. :-( Error:
TypeError: body.getElementsByTagName is not a function eval (eval at (/var/task/index.js:52:23), :16:24) process._tickDomainCallback (node.js:407:9)
Unfortunately - there is no JS DOM API in the Code by Zapier triggers or actions (that is because it isn't run in a browser and doesn't have the necessary libraries installed to fake it).
You might look at Python and instead, and https://docs.python.org/2/library/xml.etree.elementtree.html. Decent question and answer is available here Python Requests package: Handling xml response. Good luck!
Any function not supported by Zapier will result in a TypeError. I needed to use a regular expression to achieve this.

Protractor-cucumber: isPresent is not function

I have my code:
this.Then(/^I should see "([^"]*)" link$/, function (callback) {
var logoutpath = by.xpath('//div[#id="account_logout"]/a');
browser.wait(function() {
return dv.isElementPresent(logoutpath);
}, 30000);
browser.driver.isElementPresent(logoutpath).then(function(isPresent){
expect(isPresent.isPresent()).toBe(true);
browser.driver.findElement(logoutpath).then(function(start){
start.click();
});
});
browser.sleep(2222);
console.log(">>>>>>>"+browser.getTitle());
callback();
});
when i run and get error in console:
TypeError: isPresent.isPresent is not a function
at c:\Users\binhlex\WebstormProjects\untitled\Feature\Steps\login_steps.js:33:30
at [object Object].promise.ControlFlow.runInFrame_ (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
at [object Object].goog.defineClass.notify (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
at [object Object].promise.Promise.notify_ (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
at Array.forEach (native)
I have some question?
- Why didn't i use isPresent method?
- When i run console.log(">>>>>>>"+browser.getTitle());, why it display >>>>>>>Promise::222 {[[PromiseStatus]]: "pending"}, how can i use it to verify with expected title of the page?
To your latest question, because browser.getTitle() is a promise, if you want to console.log Title you'd have to do: browser.getTitle().then(function(title){console.log(title)});
For your first question, I don't get why you are trying to obfuscate the code so much. in protractor you don't have to wait for element before clicking it. ( if you don't have ignore synchronization on).
So this:
browser.driver.findElement(logoutpath).then(function(start){
start.click();
equeals:
logoutpath.click()

nodejs scrypt crashes without error

I am using nodejs library scrypt to hash my passwords.
scrypt.hash(new Buffer(data.password), scryptParameters, function(err, res) {
console.log(res);
//scrypt.verify(res, "incorrect password");
});
which works perfectly. But, the problem is when I uncomment the line to verify the hash (I have put it in the same function (and syncronously) just for the sake of simplicity)
The script just crashes without any errors! this is what I get in the console
/Users/foo/Documents/nodejs/wow/models/user.js:44
scrypt.verify(res, "incorrect password");
^
[object Object]
31 Jul 10:26:52 - [nodemon] app crashed - waiting for file changes before starting...
also it seems like it is trying to put some sort of object, that is [object Object]. I am not console.log'ing it, as I get nothing in the console before uncommenting that line.
Anyone had the same problem? Thanks in advance.
The problem is that you're using the wrong key encoding for scrypt.verify(). By default it expects a Buffer, but you're supplying a string. Either change the "incorrect password" to be a Buffer or do this:
scrypt.hash(new Buffer(data.password), scryptParameters, function(err, res) {
scrypt.verify.config.keyEncoding = "utf8";
scrypt.verify(res, "incorrect password");
});

Node-Webkit with external module containing native code

I'm using node-webkit with an external module called edge.
According to the node-webkit docs modules that contain native code must be recompiled using nw-gyp as oppose to node-gyp. I was able to recompile without error and node-webkit seems to import the module OK.
Heres my code. The code I'm trying to use:
var edge = require('edge.node');
var hello = edge.func(function () {/*
async (input) =>
{
return ".NET welcomes " + input.ToString();
}
*/});
hello('Node.js', function (error, result) {
if (error) throw error;
console.log(result);
});
Which throws the following error when run within node-webkit.
Uncaught TypeError: Object [object Object] has no method 'func'
If write the object out to console.log I can see:
Object {initializeClrFunc: function}
initializeClrFunc: function () { [native code] }
__proto__: Object
So the module seems to have loaded. If I run the same code outside of node-webkit, everything works perfectly and I can access the func function. This is driving me crazy - and any help would be really appreciated.
func method is provided by edge.js, the wrapper around edge.node native module. So you should replace require('edge.node') by require('edge').

Resources