Interacting with a flash application using python - python

I'm contemplating using python for some functional testing of flash ad-units for work. Currently, we have an ad (in flash) that has N locations (can be defined as x,y) that need to be 'clicked'. I'd like to use python, but I know Java will do this.
I also considered Jython + Sikuli, but wanted to know if there is a python only library or tool to do this. I'd prefer to not run Jython + Sikuli if there is a native python option.
TIA.
#user1929959 From the pyswftools page, "At the moment, the library can be used in Python applications (including WebBased applications) to generate Flash animations on the fly.". And from the bottle-flash page, "This plugin enables flash messages in bottle.". Neither help me, unless I'm overlooking something ...

There are a number of ways I've seen around the net, but most seem to involve exposing Flash through JS and then using the JS interface, which is a bit of a problem if you are trying to test things that you don't have dev access to, or need to be in a prod-like state for your tests. Of course, even if you do that, you aren't really simulating user interaction, since you are working through an API.
If you can reliably model your Flash components with fixed pixel positions relative to the page element the Flash component is running in, you should be able to use Selenium Webdriver to position the mouse cursor and send click commands without actually cracking Flash itself. I'm not 100% sure that would work, but it seems at least worth a shot. Validation will be a bit trickier, but I think you should be able to do it with some form of image comparison. A few of the Flash automators I saw are actually using image processing under the hood to control both input and output, so it seems like a legitimate way to interact with it.

Related

Is Python ideal for this web project?

I'm working on a school project which I would like to showcase in a web browser or application.
I would like the user to control the work with a mouse or keyboard. I want to show a unique image based on where the curser is over a visible grid. An additional feature is the ability to switch to a different "stack" of images upon user input from the scroll wheel or in a dialog.
I have a beginner-intermediate understanding of Python.
Theoretically, I could write this using Sage, but I would like the feedback to be instant - a change shouldn't require a new calculation, just show a new image.
Additionally, I would like to create a feature which takes the user on a "tour" based on information attached to an image.
My first thought was to use an online website builder (Webflow), though an opportunity to learn a new language or expand upon my knowledge of Python is my first choice.
What language is best suited for this?
This is possible in Python, as nearly everything is (Python is a Genral Purpose Language), so you could certainly implement this in Python.
The best language for this, however,IMO, would be JavaScript.
Python will almost certainly get in your way or at least hinder you slightly in comparison.
An 'online website builder' is not likely to provide you with the required amount to control needed to implement you project - most of these are painfully simplistic drag-and-drog tools where any real control only comes from adding your own CSS/HTML/JS anyways.
JS is an incredibly useful language and also very well suited for nearly all web/browser projects, so use this opportunity to learn it !
Further, React Native can let you use JS for mobile apps too, if that's what you meant by 'applications' or you could simply keep it a web app.
PS. This may also be possible with HTML5, which is perhaps simpler and easier to learn, but I'm no a web dev so that will have to be confirmed by someone else.
I am sure, though, that this is very efficiently doable in JS.

Automate webpage tasks without having to have a browser open?

I know about tampermonkey/greasemonkey and have used it a fair bit, but now my task is to write a program that runs in the background and automates mundane tasks (clicking buttons, typing into input fields etc.) on a specific webpage. Running a browser in the background takes too much RAM and processing power, so I'm looking for an alternative.
So far I've found selenium, but after a bit of research it looks like that it requires to have a browser open at all times as well (or maybe not? the documentation isn't that good). I thought about python scripts too, but I don't have any experience with those nor have I any idea if they can handle anything that's not basic html. If they can, does anyone know of a good tutorial for python scripts? I have used that language a few years ago, so I shouldn't really have a problem with python itself.
If python scripts aren't ideal either, is there a (preferably somewhat simple) way I could achieve what I want?
It depends on whether you want a script that interacts with a web UI, or a script that automates web requests. Do you really need to click buttons and type into input fields? Presumably, the data from those buttons and input fields is eventually sent to a web server. You could skip the entire UI and just make the requests directly. You don't need a browser for that and python is fine for doing these types of things (you don't even need selenium, you can just use requests)
On the other hand, if you're trying to test out the UI of a web page, or you actually need to interact with the web UI for some other reason, then yeah, you'll need an application (like a web browser) that's capable of rendering the UI so you can interact with it.

I want to setup and manage my own local 'autocomplete', so I can fill in the correct box with a password

It seems like passwords are always getting compromised. I want to write a program, preferably in C/C++ or Python, that I can use to fill in my passwords on the various sites I visit but do so from a program I manage on my machine that stores my pws and logins locally.
The reason a program is the best idea would be so that I can make very strong passwords and change them often. I would be able to choose my own encryption for the local storage/database. I would also be able to manage a schedule to keep passwords young.
I am asking the question because I haven't had much luck looking for a starting point. For instance, can I use Python to ask my browser for a list textboxes on a page I have open in a browser? Can I fill in the text boxes and click buttons from code that runs independent of the browser?
It didn't look like Google Python API was right, and I don't know that JS would act like a console app. Maybe Selenium and Python?
A good answer for me would be languages and platforms that would meet these requirements. I'm open to learning a new language or using a different browser, but I have no idea where to start.
Thanks in advance!
Although there are ways to control your browser from a local Python/C/C++ application (see mechanize, from insepctorG4dget's comment), you would have a much easier time with an extension.
First of all, you wouldn't have to use some roundabout route, and instead, you could use well documented APIs. I'm not sure about other browsers, but I know that Chrome and Firefox both would be easy to make this in.
For storage, Chrome has the filesystem API and Firefox has the file API. Chrome also has the chrome.storage API, and if you use Chrome Sync, this could come in handy.
Extensions are made in HTML/CSS/JS, but the amount of HTML and CSS required for the type of extension you're looking for is a piece of cake, and if you're familiar with both Python and C, JS would be quite simple to pick up. You could also use a language that compiles to Javascript- there are tons out their.
There are plenty of libraries that would make your task easier in JavaScript than in some other library- for DOM access, of course, their's JQuery, and for encryption, there's sjcl. If you want a random password generator, of course, you could just use Math.random, in the core/built-in JS library.
Security
If someone wanted to steal your password from your local computer, a local application may be easier to steal from, as all the data is stored locally (although if it is encrypted, this wouldn't be so much of a problem). Locally stored passwords would be extremely hard to hack from externally, because the hackers would have to know exactly how your extension was implemented, and find some bug to exploit- near impossible if you do a decent job.
If you use Chrome's autocomplete, then it should be pretty secure from hackers- a popular browser like Chrome would have to be secure, but I have no idea how it was implemented, so you should probably double check on this. Just remember though, all of your passwords are being sent to advertisers and the NSA. ;)
An extension probably would be the least secure, since it may be vulnerable to both external and local attacks. However, again, either a local program, or an extension, you don't need worry unless:
You're doing something "Quick and Dirty"
You're not encrypting it
Some major organization with professional hackers wants all of your personal information

Python: communicating with window application

Im trying to communicate with a windows application with python. Need to fill in text fields and retrieve results (which are also displayed in text fields).
Currently using PywinAuto, works perfectly but its too slow for my purpose. Filling in 6 textfields and pressing two buttons takes 2 to 3 seconds... Im looking for a way to speed this up.
What is the fastest way to control and retrieve data from a windows application, that is feasible for a beginner in Python?
Thanks in advance.
This is very difficult. PywinAuto is one of the best ways to handle this kind of problem, but you have to be very careful about which Windows application you are working with. This is because not every Windows application will "publish" it's controls in a reliable way for you to automate. This is particularly true of Mozilla Firefox. However, the Microsoft Office suite does consistently publish just about every control and button on each of its interfaces that I have ever seen. Thus, the real problem is not with PywinAuto, or even with Windows, it is with whoever wrote the application you are trying to automate and whether or not they reliably publish the interfaces you were trying to control.
The other question you have to ask yourself is how you are populating the text fields and what is actually taking the time. Filling in fields and buttons should take a fraction of a second if they are independently workable. Otherwise, there is probably something else going on that you should investigate.
Good luck. This is a really tough problem.
I have been using pywinauto for 1.5 years. And I have tried lots of different tools for UI automation. You know what, pywinauto not the slowest among them.
Ofcource some actions can take a long tome (seconds), but as a rule it is a high weith actions, such as count children, etc.
Please be sure you do not call findwindows method when it is not realy need.

python script output to webpage

I wrote a python script that reads in text from a file and writes a text file of definitions. I want to somehow integrate my program with a webpage for the whole world to see.
I want to be able to retrieve input text from one text box, have the python script process it, then display the output in the other text box.
I have done quite a bit of research thus far but I am still unsure of the best way to go about doing this. I tried using google's app engine but encountered too many problems, for example the app engine runtime environment uses python 2.5.2, I wrote my program using 3.1.2. Other than that I just felt that I was beginning to waste my time trying to port my program over.
I'm starting to think that javascript is the way to go or maybe pyjamas. I was also wondering if it would be possible to just have the python program constantly running on the server and to perform a system call.
I posses very little knowledge when it comes to web development. I appreciate any advice.
You could use the cgi module and create a CGI script, if your server supports it.
It's a much bigger question, involving:
Where are you going to host the site,
How slow is the script (can it execute in a few seconds or not),
Does it need access data from files or a database,
How complex is it,
etc.
I would suggest you read about Django:
http://docs.djangoproject.com/en/1.2/
That is probably the easiest way to set up a simple web site, but is also very powerful if you want to do something more in the future (related to this project or not).
However, since your script is Python 3 only, you don't have too many options, see this question:
https://stackoverflow.com/questions/373945/what-web-development-frameworks-support-python-3
I suppose, if not too hard, it is worth thinking about converting it to Python 2.7.
If that is an option, then you might very well go down to Python 2.5 and use Google App Engine. It gives you many things for free and you really don't need to worry about many things that you would if you were to set up your server. It includes a modified (better to say, shrunk down) version of Django 1.1. When you say you are wasting your time porting from 3.x to 2.5, I guess you were not counting the time that you will waste setting all other things up.

Categories