Showing progress view when communicating with web-service - web-services

in my application start, i'm requesting data and parsing by communicating with web-service via JSON, this work takes sometime 2 seconds, so i want to show the user a UIProgressView when this work is being executed and when it's done, i will redirect the user to the main view of my application, can you please help me there ? what objects to use essentially and if you have tutorials tips, i wil be glad, thx in advance :)

Look into ASIHTTPRequest. You're going to want to use the setDownloadProgressDelegate: method to hook it up to your progress indicator. Something like this:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadProgressDelegate:someProgressIndicator];
[request startSynchronous];
For further reading see the relevant portion of the documentation here:
http://allseeing-i.com/ASIHTTPRequest/How-to-use#tracking_progress

Related

Python Selenium Alert Authentication Trouble

I am trying to access a website that requires a login thru an alert box such as the one below:
I have tried to look up many different ways to do this and they dont seem to work. what i have tried are listed below:
Didnt work and gave me the same login alert.
start_url = 'http://username:password#example.com'
agent.get(start_url)
Keep getting an error message saying "NoAlertPresentException: Message: no alert open"
start_url = 'http://www.example.com'
alert = agent.switch_to_alert()
alert.send_keys("username")
alert.send_keys("password")
Get an error saying webdriver has no attribute "switchTo"
start_url = 'http://www.example.com'
agent.switchTo().alert().sendKeys("username")
I have to use Chrome because of the versions of IE and Firefox I have and can get, do not support the functions in the site
I have been having this exact same issue for some time now - with my end goal being to do this headless (in the background without visually launching an instance of Chromedriver).
Non-Ideal Solution 1:
I first used a library called pynput to automatically type the credentials in to the alert box and click the ok button, it was pretty simple to get working but:
still didn't work headlessly
I had to be focused on the browser or it would type the credentials elsewhere
This worked great in the meantime as everywhere I looked online it seemed like there was nothing I could do to overcome authentication alerts headlessly...
I'm a relative beginner (started programming <1 year ago) so perhaps I just wasn't looking in the right places!
I've now solved this issue though like so:
First I logged in to the alert as normal on Chrome while monitoring the Network section of devtools to get a good look at the GET request for the protected page screencap here:
Upon seeing that the Authorization was Basic (this will work for Bearer too) I tested just copying the same request in Postman with this header and it worked! Now if only there was a way to make http requests from Selenium???
I first tried the library selenium-requests (which didn't work for me: I got the same error as this person https://github.com/cryzed/Selenium-Requests/issues/33
This library seems absolutely excellent and exactly what I needed, I just don't currently have the know-how to get past firewalls/whatever was stopping me at this stage...
What eventually worked for me was the library selenium-wire. I followed this guide https://pypi.org/project/selenium-wire/#intercepting-requests-and-responses to have the webdriver navigate to the protected page as normal, but intercept the request and add the Authorization header before sending it :) now this works for me totally headlessly. Granted, this won't work on more secure websites but I hope it helps someone having the same issue.
This is Pythoncode
Problem with alert boxes (especially sweet-alerts is that they have a
delay and Selenium is pretty much too fast)
An Option that worked for me is: (just exchange the button click in the end with whatever action you want to have)
while True:
try:
driver.find_element_by_xpath('//div[#class="sweet-alert showSweetAlert visible"]')
break
except:
wait = WebDriverWait(driver, 1000)
confirm_button = driver.find_element_by_xpath('//button[#class="confirm"]')
confirm_button.click()
Note to 2: Here is probably the error due to the alert taking more time to load than the single elements (such as username, etc.)
Note to 3.: I think it should be switch_to

Eclipse Scout get Desktop on page

I am looking for a way to get current Desktop() inside page.
I know I have getOutline(), but I need Desktop().
Is there a way to get it?
The session know the desktop
The current thread (the scout job that is running) knows the session
Here is one possibility that is working anywhere in the Scout model code:
ClientSyncJob.getCurrentSession().getDesktop()

customize user to user request

Is there a way to customize the user to user request link in the notification the recepient receives in his/her notifications jewel? I'm trying to direct the receipient of the request to a specific competition room upon clicking on the notification.
Example - A request is sent to the user to be a pitcher in a particular baseball game (Yankees vs. cubs), can the user request notification take him to the particular baseball game and not just the home page or game directory? Otherwise how will the player know what the request is for or where to go upon ariving on the home canvas page?
Thank you in advance!
I know I am very late answering this question. But I too faced a lot of difficulty figuring this out at the beginning. I hope my answer would help others facing the same difficulty too.
There is a data parameter for each request object. You can find out about the parameters here. This can be used to track which object is being sent/received. For example, you can use an integer or a string on your client side to tell you which kind of object the particular request is. The sample FB.ui call may look like this:
var obj = {
method: 'apprequests',
title: 'Here\'s something to help you out.',
message: s_message,
data: i_giftIndex
};
FB.ui(obj, GiftCallback);

Selenium wait for download?

I'm trying to test the happy-path for a piece of code which takes a long time to respond, and then begins writing a file to the response output stream, which prompts a download dialog in browsers.
The problem is that this process has failed in the past, throwing an exception after this long amount of work. Is there a way in selenium to wait-for-download or equivalent?
I could throw in a Thread.sleep, but that would be inaccurate and unnecessarily slow down the test run.
What should I do, here?
I had the same problem. I invented something to solve the problem. A tempt file is created by Python with '.part' extension. So, if still we have the temp, python can wait for 10 second and check again if the file is downloaded or not yet.
while True:
if os.path.isfile('ts.csv.part'):
sleep(10)
elif os.path.isfile('ts.csv'):
break
else:
sleep(10)
driver.close()
So you have two problems here:
You need to cause the browser to download the file
You need to measure when the downloaded file is complete
Neither problemc an be directly solved by Selenium (yet - 2.0 may help), but both are solvable problems. The first problem can be solved by GUI automation toolkits, such as AutoIT. But they can also be solved by simply sending an automated keypress at the OS level that simulates the enter key (works for Firefox, a little harder on some versions of Chrome and Safari). If you're using Java, you can use Robot to do that. Other languages have similar toolkits to do such a thing.
The second issue is probably best solved with some sort of proxy solution. For example, if your browser was configured to go through a proxy and that proxy had an API, you could query the proxy with that API to ask when network activity had ended.
That's what we do at http://browsermob.com, which is a a startup I founded that uses Selenium to do load testing. We've released some of the proxy code as open source, available at http://browsermob.com/tools.
But two problems still persist:
You need to configure the browser to use the proxy. In Selenium 2 this is easier, but it's possible to do it with Selenium 1 as well. The key is just making sure that your browser launcher brings up the browser with the right profile/settings.
There currently is no API for BrowserMob proxy to tell you when network traffic has stopped! This is a big hole in the concept of the project that I want to fix as soon as I get the time. However, if you're keen to help out, join the Google Group and I can definitely point you in the right direction.
Hope that helps you identify your various options. Best of luck!
This is Chrome-testing-only solution for controlling the downloads with javascript..
Using WebDriver (Selenium2) it can be done within Chrome's chrome:// which is HTML/CSS/Javascript:
driver.get( "chrome://downloads/" );
waitElement( By.CssSelector("#downloads-summary-text") );
// next javascript snippet cancels the last/current download
// if your test ends in file attachment downloading
// you'll very likely need this if you more re-instantiated tests left
((JavascriptExecutor)driver).executeScript("downloads.downloads_[0].cancel_();");
There are other Download.prototype.functions in "chrome://downloads/downloads.js"
This suites you if you just need to test some info note eg. caused by file attachment starting activity, and not the file itself.
Naturally you need to control step 1. - mentioned by Patrick above - and by this you control step 2. FOR THE TEST, not for the functionality of actual file download completion / cancel.
See also : Javascript: Cancel/Stop Image Requests which is relating to Browser stopping.
This falls under the "things that can't be automated" category. Selenium is built with JavaScipt and due to JavaScript sandbox restrictions it can't access downloads.
Selenium 2 might be able to do this once Alerts/Prompts have been implemented but that this won't happen for the next little while yet.
If you want to check for the download dialog, try with AutoIt. I use that for uploading and downloading the files. Using AutoIt with Se RC is easier.
def file_downloaded?(file)
while File.file?(file) == false
p "File downloading in progress..."
sleep 1
end
end
*Ruby Syntax

Django - Send Output Continually

I want to start processing some files from a django view and I want to be able to send the name of the files to the browser as they are processed. Is there a way to do this (easily)? I could probably do this using threads and ajax calls, but I want the simplest solution for now.
I found what I needed in an answer from one of the links that Andre Miller provided.
I found out that's possible to pass an iterator to HttpResponse so I used this code and it worked:
def import_iter():
""" Used to return output as it is generated """
# First return the template
t = loader.get_template('main/qimport.htm')
c = Context()
yield t.render(c)
# Now process the files
if req.method == 'POST':
location = req.POST['location']
if location:
for finfo in import_location(location):
yield finfo+"<br/>"
return HttpResponse(import_iter())
You would need to use some sort of queuing process if you want to kick off the task when the view is rendered, otherwise the process will finish first before anything is returned to the browser.
Once the task is running asynchronously you could use either AJAX to update the page with the latest status or simply use a meta-refresh inside the page to load the new content.
There is Django queue server here you could use:
http://code.google.com/p/django-queue-service/
It would seem that this question has also been asked a few times before:
How to best launch an asynchronous job request in Django view?
Is there any way to make an asynchronous function call from Python [Django]?
How do you do something after you render the view? (Django)
We are in 201X
Yes, you should use WebSockets or Ajax calls !!
Since you were asking(for the record purpose) for some streaming solution in Django you can use StreamingHttpResponse which Django supports out of the box.
https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.StreamingHttpResponse
The StreamingHttpResponse class is used to stream a response from Django to the browser. You might want to do this if generating the response takes too long or uses too much memory. For instance, it’s useful for generating large CSV files.
If you clear the output buffer, then you should be able to see what has been processed.
First of all, make sure you output a Connection: Keep-Alive header, after which you just have to make sure that the script output isn't being buffered. In Python, you can use the cgi module's cgiprint function to ensure that Python's buffer is cleared, but you should also check the web server configuration, as some will buffer all output until the script finishes running.