I,m new using cypress and i need help to handling window prompt. I don,t know how to accept o cancel the following screenshot. Thank you Prompt
That ptompt is impossible to select any button, has no DOM, i tried cy.contains, cy.stub
Which version of cypress do you have?
You could try directly login without filling out the login:
cy.request({
method: 'POST',
url: `YOUR URL OF CURRENT PAGE`,
body: {
userName: 'yyy',
password: 'xxx',
},
});
After that you need a cy.visit('URL AFTER LOGIN')
Related
i'm trying to test an application using cypress. I have an odd scenario where i have an html form with an action tag, some fields in the form and then a button for submit it.
I'm filling out all the fields in the form and click the button for submission, but i'm getting this error:
I don't wanna wait for the response, cause in this odd case the response is redirecting for a page i don't have access and the test fails, i'm just want a check the form submission response by checking something simple, for instance the response status.
Any help will be welcome...
Thanks in advance..
Can you try the below cy.request() method. I don't know if there is any authorization needed for your request. Give a try as below and let me know.
it('Check response status', function () {
cy.request({
method: 'post',
url: 'url_here',
form: true,
headers: {
accept: "application/json",
},
}).then((response) => {
expect(response.status).to.eq(200);
})
})
I have a website in localhost:8080, that has a window to log in to Facebook. When I make the request like this:
function fb() {
$.ajax
(
{
type: "POST",
url: "https://www.facebook.com",
data: {
username: $("input[name = 'username']").val(),
password: $("input[name = 'password']").val()
},
success: function(data, text, status) {
alert(status.status);
}
});
}
it keeps returning me 200 status even if I provide incorrect details. I suppose it just returns me the whole page...
How can I make this work? I want the Facebook page opened and logged in if credentials are correct and if credentials are wrong, I want error code to be returned.
You cannot use ajax to post to another domain or the server has to enable CORS for your domain. But you can use the FB login: https://developers.facebook.com/docs/facebook-login/web/login-button
I'm having issues making an authenticated Jenkins API call - I'm trying to retrieve some JSON data. I'm using it on a webpage with jQuery - anyone with Jenkins experience, any ideas?
Note: the password is the user API key from Jenkins.
$.ajax
({
type: "GET",
url: "http://jenkinsurl/build3/testReport/api/json",
dataType: 'jsonp',
username: "jenkinsusername",
password: "1axxxxsdasde3ad8",
success: function (){
alert('To test it worked');
}
});
Thanks
I've been doing something similar; ran into all sorts of issues. Documentation is scanty on this sort of thing. But finally got it working, at least on my Jenkins. There's a possibility that the following won't work with every Jenkins authentication plugin; I've only tested against the built-in authentication and the scripted authentication.
To authenticate, do the following in your java script:
$.ajax(jenkins_relative_url + 'j_acegi_security_check', {
type: "POST",
dataType: "text",
async: true,
headers: {
"Content-type": "application/x-www-form-urlencoded"
},
data: {"j_username": username, "j_password": password},
});
The ajax call above would get cookies loaded up that Jenkins uses to determine if you are authenticated. After that, you could do the same $.ajax calls you where making, but without the username and password parameters. You should only need to authenticate once, then make any number of calls against Jenkins - as long as you carry around those cookies.
Let me start by saying that I know the difference between .ajax async:true an false, AND that I understand that it is GENERALLY not advisable to use synchronous calls. With that said, I think I have a situation that calls for using async:false.
The basic problem is that I need to click a link (or button...or anything) and have the form data saved and when it is finished saving I need a new TAB opened in my browser (we use Chrome). This sounds simple, but the issue I have is that if I use a callback with .ajax and async:true I have to use location.open and that opens a new window (in chrome). This not acceptable to my end users. ALL other links open in new tab..
Here's where I am stuck... If I call the async:true ajax onClick of a link, but don't use a callback, I just return true, It works and opens in a new tab. But I have no guarantee that the data was saved in time for the new window to render the report base on it. So I switch to async:false, and then I can make sure it works BUT it opens a new WINDOW not a TAB. I certainly don't want to just loop and wait until the async:true returns...
What can I Do?
Here is the html Link:
<a id="btnSampleForm" href="/Report/Pdf?template=xyz....." target="_blank">Sample Form </a>
Here are my two codes functions. Both save the data, but one opens in new tab, and one in new window.
This one Opens in new window...and I want it to open in new tab.
$('#btnSampleForm').click(function(e) {
var retval = false;
var request = $.ajax({
type: "PUT",
url: "/api/projects/#Model.ID",
data: $('#project_form').serialize(),
dataType: "json",
traditional: true,
async: false
});
request.success(function(x) {
retval = true;
dataChanged = false;
});
request.error(function (x) {
alert('There was a problem saving the record. Please try to save the record manually before opening this report.');
retval = false;
});
return retval;
});
This one opens in new tab but I can't use it because I can't guarantee the save is done.
$('#btnSampleForm').click(function(e) {
$.ajax({
type: "PUT",
url: "/api/projects/#Model.ID",
data: $('#project_form').serialize(),
dataType: "json",
traditional: true,
async: true
});
return true;
});
I'm try to POST data with ajax by using DOJO(v. 1.8.1)
request.post("http://someweb.com/service", {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
handleAs: "text",
sync: false
}).then(function (text) {
console.log("The server returned: ", text);
});
When POST a data it doesn't show a log message in Tab Console of FireBug but shows in Tab Net instead.
NOTE : I'm already require "dojo/request" and log on dojo ready it's working OK. No any error.
Why it shows in Tab Net and how can I fix it? I have no idea what wrong with my code.