How to switch to an iframe whose id is stored in a variable in karate? [duplicate] - karate

Api returns a confirmationNumber, which i'm storing in a variable then using that confirmationNumber to click and assert on the UI page.
def myFeature = call read('Feature1.feature')
def confirmationNumber = myFeature.confirmationNumber
//some ui login steps are here
Then input('#paymentNum',confirmationNumber) //--successfully entered confirmationNumber
And assert exists('{div}confirmationNumber'). //--not successful. not able to read the stored value
And click('{a}confirmationNumber') //--not successful. not able to read the stored value
Please help
Thank you

Easy. Think of anything within the ( and ) as pure JavaScript. Also please note the extra exists, hmm maybe I should re-design that part of the API - and thanks for asking this question ! https://github.com/intuit/karate/issues/1148
# this is how to use exists() right now, but I have decided to change this !
And assert exists('{div}' + confirmationNumber).exists
And click('{a}' + confirmationNumber)

Related

Cypress Assertion

I have a question regarding Cypress assertions, just recently start playing with this testing platform, but got stuck when the URL returns a random number as shown below.
/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=SK42f-DZ_iCk2oWE8DVNnr6gAArG277W3X0kGJL1gTZ7W5oQAAV9iC4Zng4mf0BlulglN-10NK&dojo.preventCache=1575947662312
As you can see token is random and dojo.preventCache is also a random string. I want to detect this url and check if deep=true regardless the token number, but I don't know how to achieve this.
cy.location('origin', {timeout: 20000}).should('contain', '/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=**&dojo.preventCache=**');
Anyone any idea?
You can check both the path and query like this (note that cy.location('origin') doesn't yield neither pathname nor query from your original question, so I'm using cy.url()):
cy.url()
.should('contain', '/Geocortex/Essentials/REST/sites/SITE')
.should('contain', 'deep=true');
or check each separately:
cy.location('pathname').should('contain', '/Geocortex/Essentials/REST/sites/SITE');
cy.location('search').should('contain', 'deep=true');
or, use a custom callback in which you do and assert whatever you want:
cy.url().should( url => {
expect(/* do something with url, such as parse it, and access the `deep` prop */)
.to.be.true;
});

APEX page process using a DB package

I am using APEX 5.1.4
Know this is probably one of those very easy answers - just not sure what script is used in a Page Process to call a DB package. Know I need to pass the parameters and call the specific part of the package - just not sure what that page process script should be.
Need to pass in the values from page 3 - :P3_USER_ID (which is the user's email address) and the :P3_PASSWORD. The DB package is called PSPRT_AUTH_PKG and the part of the package is CREATE_ACCOUNT. Thanks!!
Think I found the answer...
use this in the page processing as PL/SQL code...
psprt_auth_pkg.create_account(:P3_USERNAME, :P3_PASSWORD);
Something like (you'll need to correct my made-up parameter names):
PSPRT_AUTH_PKG.CREATE_ACCOUNT
( p_user_id => :P3_USER_ID
, p_password => :P3_PASSWORD
);

Print scenario name when running each scenario

I want to print the name of each scenario as the test run. What can i call or do to get the name so that i can execute * print <scenario_name> ?
The answer for this post is exactly what i want to do: Print scenario name Is there a way to access the Scenario object?
As of now this is not supported, but will be easy to add. But here's the question - is this just to help you make sense of the logs ? Because if you are not using the Cucumber HTML report yet, you should - and that's what most teams are using: https://twitter.com/KarateDSL/status/899671441221623809
Refer to this discussion for more: https://stackoverflow.com/a/47555173/143475
If you still really need this, kindly raise a feature request.
Edit: this will be available in the next version: https://github.com/intuit/karate/issues/257

Karate API Testing - Access variable value across scenario in a feature file

I am running into this situation (similar to this) when trying to do the following:
Scenario: Create User
Given path 'user'
And request read('user.json');
When method post
Then status 200
And def user_id = response.userId
Scenario: Test A
Given path 'user/' + user_id <- Received javascript error here
...
Scenario: Test B
Given path 'user/' + user_id <- Received javascript error here
...
Scenario: Test A
Given path 'user/' + user_id <- Received javascript error here
...
Basically what i am trying to do is create a user in my database first, then run it through a series of test and use a last scenario to delete this user. Therefore, i need to share the user_id value across multiple scenarios. Background doesn't work for me because that means i have to create a new user for each scenario. I have seen in the demo that a simple way would be to put all test under 1 scenario but i don't feel that it is right to put all tests on 1 scenario
I have reviewed the karate demo but i did not come across any sample code that will help my situation. May i know the right way to do this in Karate? Thanks.
I think you are missing the callonce keyword. Understand it and then look at the demos, for example, this one: callonce.feature.
You will need to move the 'common' code into a separate feature, but that is the right thing to do, because you will typically want it re-usable by multiple feature files as well.

Trouble inserting fbml into database

Hi I am working with the facebook javascript sdk and I am having succcess using fbml to list the logged in users name like so...
<fb:name uid="loggedinuser" useyou="false"></fb:name>
What I would like to do next is assign this value to a php variable and insert it into my database. The problem I'm having is when I assign this value to a php variable like so...
$first_name = ('<fb:name uid="loggedinuser" useyou="false"></fb:name>');
What gets inserted into the data base is the literal expression of
<fb:name uid="loggedinuser" useyou="false"></fb:name>
instead of the users real name. Is there anyway to do this with the javascript sdk? Thanks!
You need to get the variable of
<fb:name uid="loggedinuser" useyou="false"></fb:name>
before assigning it to
$first_name
FBML data is generated on the fly, there isn't a way to transfer data over like this since FBML would load later after PHP code is completed. In addition
$first_name = ('<fb:name uid="loggedinuser" useyou="false"></fb:name>');
Would never evaluate to anything other than a string, this is just how PHP works. This one line of code cannot possibly determine the nature within based on a string.
The JavaScript SDK offers a way to do this already
FB.api('/me', function(response) {
alert('Your name is ' + response.name);
});
Though this in JavaScript so you need to send the data in a AJAX call to your PHP application. It would be much easier if you just retrieved the session information after JS SDK login and let the PHP SDK take care of the rest.