How do i use parameters in cypress custom commands - testing

how do i make this work? Im trying to get the id of the object i want to get from the command parameter
photo of my code

You have to use the template literals for this:
Cypress.Commands.add('requestReport', (numeFirma, tipRaport) => {
//some code
cy.get(`[id=${tipRaport}]`)
//some code
})

Related

Cypress, how to check property exists

I'm new to cypress and am trying a couple of different methods to get a checkbox property...
checkBox().should('have.prop', 'checked')
checkBox().its('checked').should('exist')
The first line works fine but I was expecting the second to also pass but I get a "expected Undefined to exist" response.
Thanks
Assuming checkBox() function returns cy.get('.checkbox'), I think
checkBox().its('checked').should('exist')
fails because checkBox() does not return an object containing just the attributes. It returns the whole element (I think as an array). so you can't use its('checked') directly on checkbox().
Anyways, to do what you are expecting to do, you can use several methods,
using invoke('attr', 'checked')
checkBox().invoke('attr', 'checked')
.should('exist')
using getAttribute js function and expect chai assertion
checkBox().then($el => {
expect($el[0].getAttribute('checked')).to.exist;
})
using attributes in js and (its, wrap) in cypress.
Note: As mentioned earlier, you can't directly use its on the cy.get(). You need to extract the attributes from the object and use cy.wrap()
checkBox().then($el => {
cy.wrap($el[0].attributes)
.its('checked')
.should('exist')
})
you can use any of those methods, but the one I recommend is your first method.
cheers. Hope it helps.

How to show a report with dynamic parameters from a chart on Pentaho?

I have a pie chart on my dashboard, using click action, I menaged to show a report that has one fixed parameter. Here is my JS function on click action:
function showreport(scene) {
var newWindow;
if(scene.getCategory()=='POS'){
newWindow=window.open("url_report?type_lm=POS", 'REPORT');
}else{
newWindow=window.open("url_report?type_lm=NEG", 'REPORT');
}
}
This one works fine.
But now I want to pass a dynamic parameter too ( the variable obtained with query component, it is stocked in result var (code_lm):
Here is what I did:
function showreport(scene) {
var newWindow;
var code_lm=this.dashboard.getParameterValue('code_lm');
if(scene.getCategory()=='POS'){
newWindow=window.open("url_report?type_lm=POS&code="+code_lm, 'REPORT');
}else{
newWindow=window.open("url_report?type_lm=NEG&code="+code_lm, 'REPORT');
}
}
This one doesn't work, nothing is displayed by clicking the chart. I found this line var code_lm=this.dashboard.getParameterValue('code_lm'); causes the prob.
However, I do the same thing with button component :
function showreport() {
var code_lm=this.dashboard.getParameterValue('code_lm');
var newWindow = window.open("url_report?code=" + code_lm,'REPORT');
}
and it works perfectly so I wonder why this.dashboard.getParameterValue() is not working in some cases.
Can anyone tell me where comes from the problem ?
yes, if you want to pass value of parameter from query component then you need set parameter value by writing bellow code in post fetch of query component.
function fun(code_lm) {
dashboard.setParam('yourParamName',code_lm.resultset);
}
check out this may help you. How to pass a variable obtained from query component into a query on Pentaho CDE? may help you.

Cypress Get Attribute value and store in Variable

I want to get the Attribute value and store in a variable how we can achieve this in cypress
In my case I want to get the complete class value and store it in variable.
This code just give me the attribute class value but how I can store the fetch value in variable
cy.get('div[class*="ui-growl-item-container ui-state-highlight ui-corner-all ui-shadow ui-growl-message"]').invoke('attr', 'class')
I was trying to compare the style of one element with another to make sure they were equal. Here's the code that seems to work for me.
cy.get('.searchable-group-selector-card-image')
.eq(4)
.invoke('attr', 'style')
.then(($style1) => {
const style1 = $style1
})
A good way to solve this kind of scenario is to use the alias mechanism. One could leverage this functionality to enqueue multiple elements and then check all of them together by chaining the results. I've recently come to a case in an SPA where the assertion had to happen between elements that were spread across different angular routes (call them different pages).
In your use case, this would like:
cy.get('.searchable-group-selector-card-image')
.eq(4)
.invoke('attr', 'style')
.as('style_1')
cy.get('.another-element')
.invoke('attr', 'style')
.as('style_2')
// later on for example you could do
cy.get('#style_1').then(style_1 => {
cy.get('#style_2').then(style_2 => {
// Both values are available and any kind of assertion can be performed
expect(style_1).to.include(style_2)
});
});
This is described in Variables and Aliases section of the Cypress Documentation.
Here is how I got the value of for attribute in a label tag which had text "Eat" inside.
cy.contains('Eat').then(($label) => {
const id = $label.attr('for');
}
Most important thing is to get the selector right, so it exactly finds the value you are looking for. In this case you already found it. By using then() gives you the ability to store it in a variable.
cy.get('div[class*="ui-growl-item-container ui-state-highlight ui-corner-all ui-shadow ui-growl-message"]').invoke('attr', 'class')
.then($growl-message => {
const message = $growl-message.text()
//do the checks with the variable message. For example:
cy.contains(message)
})
Note that the scope of the variable is within the curly brackets. Thus using the variable has to be within those curly brackets.

react-native I do not understand the sentences

I just do not know how the code works in below, mind if any one can tell me how its working this?? I do not understand especially "=>" what does this do?
React.Children.map(this.props.children, (child) => {};
This is an arrow expression. It creates a function. There's nothing in the curly braces, so no code will execute. It's part of JavaScript, not React Native-related.
For example, you could write a function named myFunction like this:
var myFunction = (name) => {
console.log("Hello, " + name);
}
See the MDN docs for more info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Casperjs how do i add variable to fill form function and the send the varible externally via terminal

With casperjs, how can i add variable to fill form function and the send the variable externally via terminal.
I list the code i have for form fill below. I want to be able to add variables to it then pass these via command line. Any help would be appreciated.
casper.thenOpen(url2, function(){
this.fill('form[name="LoginForm"]', {
'username': 'var1here',
'password': 'var2here' },
true);
});
Once i have the variable setup, how do i pass these via command line?
Thanks in advance
Another way is to use named parameters :
var userinput = casper.cli.get("userinput");
var passinput = casper.cli.get("passinput");
And call your script like this :
casperjs test.js --userinput=test --passinput=test
In your script you will be able to test if the params is set like this
if (casper.cli.has("userinput")) {
}
if (casper.cli.has("passinput")) {
}
More information about casper.cli there => http://docs.casperjs.org/en/latest/cli.html
I achieved this and got it working by adding the following snippets of code into the right place in my casperjs script :
var userinput = casper.cli.get(0)
var passinput = casper.cli.get(1)
Then i just set my fill form section like this :
casper.thenOpen(url, function(){
this.fill('form[name="LoginForm"]', {
'username': userinput , <-- this being (0) if you use this function remove this-->
'password': passinput , <-- this being (1) if you use this function remove this-->
true);
});