I have a use-case where, I will fill the career form on the given site through selenium web-driver, after that when i will click on the submit button, I want to know, whether the form is successfully submitted or not.
Basically there are 2 cases possible in this case,
a) site populate error through java-script on career page
b) front-end make a call to server in form of ajax request, and get some response.
Is there any way, by which i can identify, whether browser is making a ajax call on click or not, and if it is making ajax call, response status code of that call?
In my project I'm using something like this:
object response = ((IJavaScriptExecutor) Driver.WebDriver).ExecuteAsyncScript(
"var url = arguments[0];" +
"var callback = arguments[arguments.length - 1];" +
"var xhr = new XMLHttpRequest();" +
"xhr.open('GET', url, true);" +
"xhr.onreadystatechange = function() {" +
" if (xhr.readyState == 4) {" +
" callback(xhr.getAllResponseHeaders());" +
" }" +
"};" +
"xhr.send();", url);
You can change xhr.getAllResponseHeaders() to get all response not only header.
After that you can serialize response, or even parse it and try to find text
Related
I'm trying to get a bot to "click" a button on an interactive message in Slack (preferably as a bot, but using a user token works too).
I've found that the link to send the action information to be
https://blue-hybrid.slack.com/api/chat.attachmentAction
My problem is I can't find any documentation for "chat.attachmentAction." Looking at the request sent when using my browser, it has one http argument: "_x_id" and the payload is a WebKitForm, containing 4 items: payload, client_id, payload_id, and token.
I'm sure if I'm just not sending the appropriate data or authentication or what. All of my POSTs return "invalid_payload" or "invalid_arg_name."
Any help is greatly appreciated.
Looks like I figured it out, finally!
I had to work it out the old fashioned way. Slack Customer Support would only help with the official public API. I'll leave the solution here in Javascript.
To do this, you need 3 things:
choice_num
the number of the choice within the list of options.
e.g. If a message has the buttons (from left to right): yes, no, and maybe, then yes=0, no=1 and maybe=2.
message
the json of the interactive message
SLACK_TOKEN
your slack token (not sure if bot tokens work, user tokens do however)
The method chat.attachmentAction itself requires 3 arguments:
payload
service_id AND/OR bot_user_id
token
args = encodeURI(
'payload={'
+ '"actions":[' + JSON.stringify(message.attachments[0]["actions"][choice_num]) + '],'
+ '"attachment_id":"' + message.attachments[0]["id"] + '",'
+ '"callback_id":"' + message.attachments[0]["callback_id"] + '",'
+ '"channel_id":"' + message.channel + '",'
+ '"message_ts":"' + message.ts + '"}'
+ '&service_id=' + message.bot_id
+ '&bot_user_id=' + message.user
+ '&token=' + SLACK_TOKEN
)
request_url = 'https://YOURSLACKTEAM.slack.com/api/chat.attachmentAction?' + args
then just send an async POST to the request_url and you should get back something like this:
{"replaced":true,"ok":true}
I've inherited a classic asp project and as part of the upgrade process we're moving a lot of the business logic to a REST API (WebApi 2.2)
The authorization endpoint for the api is written, and the asp site can call it, but it's very slow compared with calling directly via Postman.
(I'm a C# coder not a VBScript one so the below code may be offensive)
Asp Code:
' Send a prebuilt HTTP request and handle the response
' Returns true if the request returns a 200 response, False otherwise
' Response body is placed in Response
' ErrorMessage is set to return status text if an error code is returned
Function HandleRequest(ByRef objRequest, strBody)
set profiler = Server.CreateObject("Softwing.Profiler")
HandleRequest = False
' Add auth token if we have it
If Not m_accessToken&"" = "" Then
objRequest.SetRequestHeader "Authorization", "Bearer " & m_accessToken
End If
' Originating IP for proxy forwarding
If Not m_clientIp&"" = "" Then
objRequest.SetRequestHeader "X-Forwarded-For", m_clientIp
End If
On Error Resume Next
If (strBody&"" = "") Then
objRequest.Send()
Else
profiler.ProfileStart()
objRequest.Send(strBody)
flSendRequest = profiler.ProfileStop()
End If
If Err.Number = 0 Then
Dim jsonResponse
If (objRequest.ResponseText&"" <> "") Then
profiler.ProfileStart()
set jsonResponse = JSON.parse(objRequest.ResponseText)
flJson = profiler.ProfileStop()
set m_Response = jsonResponse
End If
If objRequest.Status = 200 Then
HandleRequest = True
m_errorMessage = ""
Else
m_errorMessage = objRequest.statusText
End If
Else
m_errorMessage = "Unable to connect to Api server"
End If
On Error GoTo 0
End Function
You can see there's some profiling code in there.
The following post request takes 392ms
POST localhost:5000/oauth/token
Content-Type application/x-www-form-urlencoded
client_id:ABCDEF0-ABCD-ABCD-ABCD-ABCDEF-ABCDEF01234
client_secret:aBcDeF0123456789aBcDeF0123456789=
username:demo
password:demo
grant_type:password
If I issue the same request direct to the Api via Postman it takes 30ms.
That's more than 13x slower.
What gives?
Edit
Raw result from Softwing Profiler:
flJson 10.9583865754112
flSendRequest 392.282022557137
So after a lengthy-ish discussion with the #J-Tolley it looks as though the issue is with the Softwing.Profiler documentation which states;
all results are given in milliseconds
even though earlier in the page it states;
has a ten milliseconds resolution
Have not used the Softwing.Profiler component alone before and would recommend anyone using in a Classic ASP environment to implement it using the SlTiming class library provided by 4GuysFromRolla.
In that article it even warns anyone using the Softwing.Profiler ProfileStop() method to;
Be aware that Softwing.Profiler's ProfileStop method returns a value in ticks (tenths of milliseconds).
I'm trying to learn to use AJAX with Rails.
Here is my client side coffeescript code:
$(document).ready ->
$("#url").blur ->
$.get("/test_url?url=" + $(this).val(), (data) ->
alert("Response code: " + data)
).fail( () ->
alert("Why am I failing?")
)
Here is my server-side Ruby code:
def url_response
url = URI.parse(params[:url])
Net::HTTP.get_response(url).code unless url.port.nil?
end
The Ruby code is being called and correctly returns the HTTP response code, but I can't do anything with the data because the client-side script says the call has failed. As far as I can see, it is not failing. url_response is being called and it is returning a value, so what exactly is failing here?
The problem was I removed the line that rendered the response. I previously had in, but thanks to Frederick Cheung's hint to check if the URL works directly in the browser, I realised that it no longer worked in the browser as it did previously, which is why I didn't think to check again!
The code below got everything working again.
def url_response
url = URI.parse(params[:url])
render :text => Net::HTTP.get_response(url).code unless url.port.nil?
end
In my application feedback form will be used .i have to send feedback information to server.please help me how to send information to server in windows phone.
You could use the EmailTask:
var emailTask = new EmailComposeTask
{
To = "feedback#mycompany.com",
Subject = subjectTextBox.Text,
Body = String.Format("Dear {0},/nPlease let {1}" +
" know that I would like to {2}.\nThis " +
"has been bothering me for {3} days now. " +
"I hope you can help me out. Kindest " +
"regards,\n{4}\n", toTextBox.Text,
nameTextBox.Text, activityTextBox.Text,
daysTextBox.Text, senderTextBox.Text)
};
emailTask.Show();
or you could publish a web service or you could have a web page that you point the WebBrowser control to.
It all depends on the way you want to receive the feedback and (perhaps) continue the conversation.
I have a problem with an .htaccess file. I've tried googling but could not find anything helpful.
I have an AJAX request loading pages into the index.php. The link triggering it is getting prepended by "#" via jquery. So if you click on the link domain.com/foo/bar (a wordpress permalink) you get domain.com/#/foo/bar in the browser and the content will get loaded via AJAX.
My problem is: Since these are blog posts, external links grab the real link (domain.com/foo/bar), so I want them to get redirected to domain.com/#/foo/bar (cause then ajax checks the hash and does its magic).
Example here.
The jquery code for the prepend is:
$allLinks.each(function() {
$(this).attr('href', '#' + this.pathname);
...
and then the script checks
if (hash) { //we know what we want, the url is not the home page!
hash = hash.substring(1);
URL = 'http://' + top.location.host + hash;
var $link = $('a[href="' + URL + '"]'), // find the link of the url
...
Now I am trying to get the redirect to work with htaccess. I need to check if the request is external or internal
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1 #???
and if the uri starts with "/#/" which is a problem since it's a comment then, \%23 does not really work somehow.
RewriteCond %{REQUEST_URI} !^/\%23/(.*)$ #???
How do I get this to work to simply redirect an external request from domain.com/foo/bar to domain.com/#/foo/bar without affecting the internal AJAX stuff?
I suppose your $allinks variable is assigned in a fashion similar to this:
$allinks = $('a');
Do this instead:
$allinks = $('a[href^="' + document.location.protocol + '//' + document.location.hostname + '"]');
This will transform internal links to your hash-y style only.
Ok i've done it with PHP here is the code
$path = $_SERVER["REQUEST_URI"];
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
echo "It's ajax";
} else {
if(strpos($path, '/#/') === false) {
header("Location: http://schnellebuntebilder.de/#".$path); //ONLY WORKS IF THERE IS NO BODY TAG
}
}
There sure is a better solution, but this does the trick for now and since the page /foo/bar does, in my case, not include the header.php there is no >body<-tag and the php "header()" function works . If anyone knows the htaccess script for this I am keen to know and learn.