asos add products to basket - java

I'm trying to work out on the add to basket script so I could remotely add products to the basket of ASOS from my server.
There was an API a while ago but it got closed. It's not open anymore.
I'm thinking about developing a java bot. However, I'm still hoping for an easier solution.
EDIT: in brief what i want to know is how to simulate in php the "ADD TO BAG" button pressing process that will eventually add the item to the bag.

Your question is pretty vague. That said, if I understand you correctly, you want to emulate an enduser accessing the system from a web-form. You should simply check for the form's action attribute, and do an HTTP POST to that url with the post variables filled in.
Try to look at Selenium source code btw.
I'm also pretty sure that the system uses cookies for login, so don't forget to go to login page->authenticate->grab the cookies->send it back everytime you add something to your 'basket'.

Related

Disabling the java.awt.robot inside of a browser

Would it be possible to disable a Java program that contains a Robot from running inside of a browser? I don't think so, but I figured I'd ask anyway.
For example, a robot that clicks the the "Ask Question" button on the SO site can be created in Java (based on the pixel location of the "Ask Question" button) using the Robot class. Can somebody alter the stack-overflow website such that said Java program can't run on it?
No, they could alter the site and move the button or add a captcha challenge or something like that, but essentially, to the SO servers a request from your java program looks like any other request.
Web site admins really only have the request URL and the request headers for filtering or blocking traffic. You can't manage requests from java.awt.robot directly; you'll have to look for something else to work with.

Scroll down a Webpage from a Java Desktop Application

I'm trying to read in the HTML from a webpage and parse information from it using a URLConnection in Java. It works, but the page only loads part of the content, the rest is loaded as the user scrolls down the page. Is there any way for a Java program to trigger this? My program doesn't actually open the webpage in a browser, just a connection to the page. If it's relevant, I can add the URL I'm accessing.
I've been trying to find the answer, and found a few similar topics on here, most of them without answers. However, I eventually made my way to this topic, which sounds like what I need, but I looked at the URLs of the calls being made and they're not always the same, so I can't just type them into the program. I looked at the topic it was supposedly a duplicate of, but that didn't seem to apply to my problem either, unless I misunderstood something. Is there any way to find these URLs each time the program runs, or any way to trick the connection into thinking I'm scrolling down the page? Or can I make a general "request" or "POST" as I've seen in some related topics, that will automatically call the appropriate URL (An explanation of a "POST" would be appreciated as well)?

How do I Simulate Users using Jython Script?

I need to create a user journey such as :
User is on the home page --> randomly clicks on particular item --> views the item stays for about 10 seconds --> then again goes back and clicks on another random item.
how do i generate a test script using jython? I am using Grinder tool
Shashank,
I think your question is too broad to get a detailed response. If you ask a more specific question I think you will get a better answer.
I would say there are two general approaches available for doing what you want, and you could have success with either option:
Write your test directly in Jython. The script documentation (http://grinder.sourceforge.net/g3/scripts.html) and script gallery (http://grinder.sourceforge.net/g3/script-gallery.html) will be helpful to you in this.
Using the HTTP proxy, perform the actions in a web browser that you wish your test to perform. (http://grinder.sourceforge.net/g3/tcpproxy.html) The proxy will capture your browser actions and convert them into a Jython script. After this happens, a small amount of additional work will be required on your part to modify the generated script to detect the list of items available and randomly select one.
My own personal preference is to code up the Grinder scripts from scratch. YMMV.

Interacting with an AJAX site from Java

I am trying to download the contents of a site. The site is a magneto site where one can filter results by selecting properties on the sidebar. See zennioptical.com for a good example.
I am trying to download the contents of a site. So if we are using zennioptical.com as an example i need to download all the rectangular glasses. Or all the plastic etc..
So how do is send a request to the server to display only the rectangular frames etc?
Thanks so much
You basic answer is you need to do a HTTP GET request with the correct query params. Not totally sure how you are trying to do this based on your question, so here are two options.
If you are trying to do this from javascript you can look at this question. It has a bunch of answers that show how to perform AJAX GETs with the built in XMLHttpRequest or with jQuery.
If you are trying to download the page from a java application, this really doesn't involve AJAX at all. You'll still need to do a GET request but now you can look at this other question for some ideas.
Whether you are using javascript or java, the hard part is going to be figuring out the right URLs to query. If you are trying to scrape someone else's site you will have to see what URLs your browser is requesting when you filter the results. One of the easiest ways to see that info is in Firefox with the Web Console found at Tools->Web Developer->Web Console. You could also download something like Wireshark which is a good tool to have around, but probably overkill for what you need.
EDIT
For example, when I clicked the "rectangle frames" option at zenni optical, this is the query that fired off in the Web Console:
[16:34:06.976] GET http://www.zennioptical.com/?prescription_type=single&frm_shape%5B%5D=724&nav_cat_id=2&isAjax=true&makeAjaxSearch=true [HTTP/1.1 200 OK 2328ms]
You'll have to do a sufficient number of these to figure out how to generate the URLs to get the results you want.
DISCLAIMER
If you are downloading someone's else data, it would be best to check with them first. The owner of the server may not appreciate what they might consider stealing their data/work. And then depending on how you use the data you pull down, you could be venturing into all sorts of ethical issues... Then again, if you are downloading from your own site, go for it.

Launching a website from within a program, and inputting data to specific fields

Although I've been programming for a few years I've only really dabbled in the web side of things, it's been more application based for computers up until now. I was wondering, in java for example, what library defined function or self defined function I would use to have a program launch a web browser to a certain site? Also as an extension to this how could I have it find a certain field in the website like a search box for instance (if it wasnt the current target of the cursor) and then populate it with a string and submit it to the server? (maybe this is a kind of find by ID scenario?!)
Also, is there a way to control whethere this is visible or not to the user. What I mean is, if I want to do something as a background task whilst the user carries on using the program, I will want the program to be submitting data to a webpage without the whole visual side of things that would interrupt the user?
This may be basic but like I say, I've never tried my hand at it so perhaps if someone could just provide some rough code outlines I'd really appreciate it.
Many thanks
I think Selenium might be what you are looking for.
Selenium allows you to start a Web browser, launch it to a certain website and interact with it. Also, there is a Java API (and a lot of other languages, by the way) allowing you to control the launched browser from a Java application.
There are some tweaking to do, but you can also launch Selenium in background, using a headless Web browser.
as i understand it you want to submit data to a server via the excisting webinterface?
in that case you need to find out how the URL for the request is build and then make a http-call using the corresponding URL
i advice reading this if it involves a POST submit

Categories