Trying to understand browser.elementIdText command - javascript

I couldn't find much information or useful examples to understand how this method works on a Javascript UI testing framework. I have the following element which is returned in an array:
console.log(elementarray[0]);
{ ELEMENT: '25',
'element-6066-11e4-a52e-4f735466cecf': '25',
selector: '[data="abc"]',
value: { ELEMENT: '25' },
index: 0 }
however when I run:
browser.elementIdText(elementarray[0].ELEMENT)
I see this:
{ state: 'success',
sessionId: 'af7ef2fb-7d1d-456e-ad14-c5c1fd9d83c2',
hCode: 1013623656,
value: '17:55',
class: 'org.openqa.selenium.remote.Response',
_status: 0 }
How exactly is browser.elementIdText working here, can anyone provide a simple explanation with an example pls. I see information here that I am not seeing when I log the first item in the array and surely the value of elementarray[0].ELEMENT is just 25 right? as it's shown in the first property of the object?
Thanks for any useful replies.

elementIdText expect ID as argument. In order to get ID, you need to use allElem.value[0].ELEMENT for example. See below code.
describe('allx', () => {
it('allx', () => {
browser.url("https://the-internet.herokuapp.com/");
allElem=browser.elements('//div[2]/div/ul/li/a');
console.log(allElem.value[0].ELEMENT)
text=browser.elementIdText(allElem.value[0].ELEMENT).value;
console.log(text);
});
});

Related

How to display dynamic variable in HTML

I'm wondering how to display a number in HTML that was created dynamically later on in the code. For instance I initialize the value reportDataLength in data(), and I tested that it was returning the right value by doing a console.log(), but now I want to display this value in HTML?
name: 'notification-tray',
data() {
return {
headers: [
{
text: 'Notifications',
value: 'Body',
width: '380px',
},
],
reportData: [],
reportDataLength: 0,
};
},
async created() {
await this.getReportDataLength();
},
methods: {
async getReportDataLength() {
... this.reportDataLength = this.reportData.length;
console.log(this.reportDataLength);
},
},
};
But obviously when I do something like this,
<span class="d-none">Notification Button</span>
<span class="badge">this.reportDataLength</span>
it doesn't work correctly. The other solutions I saw for similar problems used JQuery, and I feel like there's a simple way to reference this, but I can't seem to find it out.
okay so if you are using pure Javascript , u can use this in your javascript function :
Document.getElementsByClassName('badge').innerHtml=this.reportDataLength ;
otherwise if you are using vue js you can try something like this in your html file :
<span class="badge">{{reportDataLength}}</span>
You can do document.getElementById("ID-HERE").innerHTML = "new stuff", but be warned that setting innerHTML is dangerous.

Enzyme simulate with 1 node

I have the following test case in react-native.
it('changes text', () => {
wrapper.find(InputBox).simulate('change', { target: { value: 'text Given' } });
});
There are 2 InputBoxes so this gives me an error saying 'simulate should run on a single node, but found 2'.
How can I fix this issue?
You could make use of selectors such as first or at. For instance, say you want to select the first InputBox, you will write:
wrapper.find(InputBox).first().simulate('change', { target: { value: 'text Given' } });
In the same way you can use last to get the last of matched nodes or at(index) to select matches by index.

Bad Request in Discord.js (Node) and cant find out whats causing it

Im coding a bot in Discord.js (Node) and I'm trying to send an embed with the server info, I've got all the code but it keeps causing a Bad Request and I've tried everything I know here's the code:
var FieldsData = [{ name: "Channels", value: msg.guild.channels.size }, { name: "Emojis", value: msg.guild.emojis.size }, { name: "Members", value: msg.guild.members.size }, { name: "Owner", value: msg.guild.owner }, { name: "Roles", value: msg.guild.roles.size }, { name: "Region", value: msg.guild.region }, { name: "Id", value: msg.guild.id }, { name: "Icon", value: msg.guild.iconURL }, { name: "Created At", value: msg.guild.createdAt }];
msg.channel.send('', {
embed: {
color: 37119,
title: "Server info for " + msg.guild.name,
fields: FieldsData
}
});
I've tried the message with just one field and it works,
I've tried it will each field by themselves and it works
but when I put them all together they make a Bad Request,
I've checked every line, every character and I'm just
stumped at what could possibly be causing this,
the max fields is 25 and I don't have that many,
all the variables are valid, none produce 'Null' or 'Undefined',
I've tried different setups of the code layout,
I've tried adding/removing parts, editing parts, replacing bits
here and there but to no avail I cant get it to work at all.
I've been trying to figure this out for 2 hours, I've searched online, docs, etc
Please Note: I'm not that advanced with javascript so if i've made a big mistake then don't be surprised.
"msg" is the object of the message, Example:
Bot.on('message', function (msg) { /*Stuff*/ });
I hope I've explained this enough, I'm using the LATEST version of Discord.js at the time of posting this and I'm not using ANY other extensions, packages, etc
SHORT ANSWER:
Now, don't just ignore this post after I say this (actually read my reasons, the whole thing), but please just use a Rich Embed
LONG ANSWER:
First of all, I strongly suggest using Rich Embeds, as it is easier to play with and edit. Anyways, here:
The first suggestion comes from your message event. In ES6, we now have arrow functions which look like this (arg1, arg2) => {doSomething();}, and using this new feature, your message event handler should look more like this:
client.on('message', msg => {
//Do my thing with that msg object
});
Now back to the point.
Objects are weird k? I believe that this: "Server info for " + msg.guild.name is not allowed. I don't know why, but when I tried to use a variable to display my bot's version, it gave me an error too. So if you want to fix that you have two options:
Recommended: Use Rich Embeds
Not Recommended: Use `${myVar}` instead (Not Tested)
Don't overcomplicate. What is this: ('', You can just do msg.channel.send({embed:{}});
You don't just use variables for the sake of it. What is the point of using FieldsData? It is only used once, and why can't you just do:
msg.channel.send({
embed: {
color: 37119,
title: "Server info for " + msg.guild.name,
fields: [{name: "Channels", value: msg.guild.channels.size}, { name: "Emojis", value: msg.guild.emojis.size }, { name: "Members", value: msg.guild.members.size }, { name: "Owner", value: msg.guild.owner }, { name: "Roles", value: msg.guild.roles.size }, { name: "Region", value: msg.guild.region }, { name: "Id", value: msg.guild.id }, { name: "Icon", value: msg.guild.iconURL }, { name: "Created At", value: msg.guild.createdAt }]
}
});
VERY IMPORTANT NOTE:
Now, you don't give any valid reason why you don't want to use Rich Embeds, because a rich embed is also an object. ;-; So just use a rich embed.
i have scripts that require the use of objects, and they are pre made
I wonder how you get access to your embed if its not stored.... Very interesting.

Malformed request when creating billing plan

So I a using the node paypal-rest-sdk module and I'm trying to create a billing plan. Using the documentation here I made this JSON:
const billingPlanAttributes = {
name: 'Subscription',
description: 'Monthly subscription plan',
type: 'INFINITE',
payment_definitions: [{
name: 'Regular monthly infinite payments',
type: 'REGULAR',
frequency_interval: '1',
frequency: 'MONTH',
cycles: '0',
amount: {
currency: 'USD',
amount: '4.99',
},
}],
merchant_preferences: {
cancel_url: 'http://localhost:3000/subscribe/cancel',
return_url: 'http://localhost:3000/subscribe/return',
auto_bill_amount: 'YES',
},
};
But when using the paypal.billingPlan.create(... function I get the error 'MALFORMED_REQUEST', 'Incoming JSON request does not map to API request'. So I guess my JSON is not in the correct format or I'm missing something that is need.
The documentation has a charge_models key but it does not mention that it is required unlike other keys.
If you can point me in the right direction that would be great.
Edit: changed the return url and cancel url to include the full domain but still same error.
There could be more to this, but I noticed one thing wrong with your JSON. Remove commas for items last in a list. After 'amount' and 'merchant_preferences'. JSON is picky.
late answer, I know, but ran in exactly the same issue than you.
In the create function of the billing plan
public function create($apiContext = null, $restCall = null)
{
$payLoad = $this->toJSON();
$json = self::executeCall(
"/v1/payments/billing-plans/",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$this->fromJson($json);
return $this;
}
I found out, that the toJSON method always returned false. Why the hell!?!
I did the same as you did and copied the complete sample code into my code. Then it worked as expected. Now I checked, what the difference was in to my code.
I realized, that I used an umlauts (ä,ü,ö) in the name and description of the billing plan. I changed the umlauts to
'ä' => 'ae',
'ö' => 'oe'
'ü' => 'ue'
Then it worked fine! Maybe someone else is running in this issue, too.

Looping through links via WebDriver

I am currently testing a web page via WebDriver I/O. I would like to be able to select a couple of links and "click" them. Currently, I have the following:
it('Should click links', function(done) {
client
.elements('a').then(function(links) {
console.log(links);
console.log('---------');
for (var i=0; i<links.value.length; i++) {
client.getAttribute(links.value[i].ELEMENT)
}
expect(true).toBe(true);
done();
})
;
});
When I execute this test, I see the following in the console window:
{ state: 'success',
sessionId: '85d25e09-13d8-475a-81b6-87431d2d8f3c',
hCode: 1234567890,
value:
[ { ELEMENT: '0' },
{ ELEMENT: '1' },
{ ELEMENT: '2' } ],
class: 'org.openqa.selenium.remote.Response',
status: 0 }
---------
{ ELEMENT: '0' }
{ ELEMENT: '1' }
{ ELEMENT: '2' }
My question is, how do I "click" the link? When I printed out the link, I was expecting to see an ID, an href, an xpath, or some way to reference the link. But I don't see anything. When I look at the docs, they mention that the elements are returned as WebElement JSON objects. However, I can't seem to find any docs on WebElement.
What am I missing?
You tell it to click on the element, just like the docs say: http://webdriver.io/api/action/click.html
In your case, the code would be something like:
it('Should click links', function(done) {
client
.elements('a').then(function(links) {
console.log(links);
console.log('---------');
for (var i=0; i<links.value.length; i++) {
client.click(links[i])
}
expect(true).toBe(true);
done();
})
;
});
Your code will probably be different, but this should get you started. Now, a couple of quick points:
1) You should avoid having mulitple assertions inside a test. It violates OAPT and can make your tests harder to find when one is failing.
2) You might check out Protractor (http://www.protractortest.org) for E2E testing. It doesn't require Angular and it can make your testing life a lot easier.

Categories

Resources