Re-run script upon obtaining error on a webpage - java

I am using Selenium WebDriver to automate the downloading of videos from a few online video converting sites.
Basically, all the user has to do is enter the URL of a YouTube video and the program will run the script to download the videos for you.
Everything runs very smoothly, but the problem is when the website fails to convert the video.
For example, clipconverter.cc sometimes throws an "Unable to get video infos from YouTube" error, but it works when you try again.
I have done some error checking in the event that there are missing elements and the program will stop running the script but in the example I mentioned above, I want to re-run the script again.
What is a possible way of achieving this? Do I have to re-create the error page and get the elements presented there?

Since you are not using Selenium as your test engine, but as a web scraper - IMHO it's actually a matter of your workflow to handle such states. This could be a corner case of a Defensive programming, but still can design it to handle such scenarios when/if they happen.
What is a possible way of achieving this? Do I have to re-create the error page and get the elements presented there?
Once you detect such error message (via the Selenium's functionality)
when the website fails to convert the video
you can call the same piece of code that handled the first request, but this time just pass the parameters you already have (videoURL, user etc.). In case you re-try and this site still fails, you can ask another one to carry out the download (as a failover scenario).
For the design I would use a mixture of
Command to take care of the user requests/responses
Observer to notify me for the changes
State for altering the behavior when the downloading process internal state changes

Related

Webpage communicating with locally running program

I need advice how to plan to design a project. My assignment is to take data from user through webpage and pass the data as an input to a program that should run locally on the computer. I imagine it as an application (to be installed), where user would type input into specific boxes and then after clicking run, the data would be additionally modified (to ensure correctness of input and some basic transformations) go to the program (written in Java) and after the result is computed then the results would be used for another computation to make the results easily readable (depicted in graphs, known distributions, some intervals etc.), and displayed to the user (also in the form of webpage).
I am not sure what is the process, what are the programs that I need to use (preferring open source and for free) for development of such a thing. I have not done this before and I need the advice what are the topics and areas that I need to do the research in.
I imagine steps similar to those.
have html page with CSS, containing JS functionalities
(input boxes and interactive boxes for commands, such as send data)
make connection between html page and local server
send data from html form into program running on the server
let the program compute result from html input
process the result into user friendly format
send the data to be displayed on html page
(graphically readable)
get to the html page in step 1.
Is something like this functional? How can I make the Java program run locally? Friend of mine mentioned to have it run on a port (how can I accomplish that)?
I can not have it run on internet, it needs to be as secure as possible (distributed to people but used separately). I have read about sockets, would that be good use in this case?
I would really appreciate tips how to proceed further.

Cucumber, repeating login steps in all scenarios

I am using selenium with cucumber (using JAVA, but not much relevant)
Let's say I have following scenarios:
Feature: Sample Feature
Scenario: do action A on website Given website is opened And
user put correct login and pass in fields And user press login
Then do action A
Scenario: do action A on website Given website is opened And
user put correct login and pass in fields And user press login
Then do action B
Now, there will be hundreds of scenarios, and website always require to log in into the website, so I assume for each test scenario I will have to repeat login steps (for example by BACKGROUND or before scenario hook)
I have been reading that this sort of tests should be autonomous, so there should be no sharing of instance of webdriver between scenarios
Say:
Feature: Some feature
Scenario: Log into website first
Steps...
Scenario: Do action A (while we are logged already
Steps...
Scenario Do action B (all the time in same browser instance we used in
login step and action A step
Steps...
But I found people saying its not correct way, but repeating login procedure everytime I want to perform some test scenario takes a lot of time during runing many scenarios and each needs to log in first. I was thinking about enabling possibility to access website without login for testing purpose, is there any recommended approach? Thank you.
Every scenario that requires a user to be logged in will need to have the user log in. This is part of the cost of running at the integration level. However log in should not be an expensive time consuming operation, you only have to fill in two fields and submit them. It should take < 100ms to process the login.
Now for unit testing this time is huge, but for an integration test, which by its nature involves a much bigger stack and usually simulated human interaction (otherwise why do you need your user to login) this time is a relatively small component of the overall scenario run time.
Because Cucumber works at the integration level it is best not to use it as a testing tool, rather it should be used as a tool to drive development. Instead of writing thousands of small assertions (like you might when unit testing) you need to write fewer larger scenarios i.e. each scenario needs to do more. As each scenario is doing more the need for each scenario to be completely independent of any other scenario increases (the more you do, the more likely you are to be side effects on other things that are done). Sharing sessions and trying to avoid resetting the db and session between each scenario turns out to be a false optimization that creates more problems than it solves.
Its perfectly fine for a scenario to do alot before you get to its when. For example imagine the following e-commerce scenario.
Scenario: Re-order favorite
Given I have a favorite order
When I view my orders
And I re-order my favorite order
Then I should be taken to the checkout
And my favourite items should be in the basket
Now clearly an awful lot of stuff needs to happen before I can re-order e.g.
I need to register
I need to make at least one previous order
I need to choose a favorite order
and of course there are lots of other things like
there need to be products to be ordered
All of this means that this scenario will take time to run, but thats OK because you are getting alot of functionality from it. (when I wrote something similar a long time ago, the scenario took 1-2 seconds to run). The login time for this sort of scenario is trivial compared to the time required to do the rest of the setup.
I know nothing about Selenium with cucumber (but i like cucumber :-)
I'm from Selenium for Python. There I can do the following things:
from selenium import webdriver
profile = webdriver.FirefoxProfile(your_path_to_local_firefox_profile)
# like C:/Users/<USERNAME>/AppData/Roaming/Mozilla/Firefox/Profiles/<PROFILE_FOLDER>
browser = webdriver.Firefox(profile)
So, now with "[WIN] + [R]" -> Run -> "firefox.exe -p" I can create an extra profile for Selenium to use it in the code above, so I can use Firefox as well start with the profile on a trial basis. ALSO If your website with login you want to automate, cookies & cache etc. supports, then it could be that you do not have to log in via the firefox profile every time, but that the Firefox starting each time automatically logs in because he stored the login data.
I do not know if that helps, but I wanted to tell you.

Storing live TestNG Data

I'm looking for a solution to the following:
Basically I am running automated tests using Selenium & TestNG, I have a report set up and a monitor set up ( A HTML file that I can view to see the progress of my tests. ) When a test is passed/failed/skipped it gets amended to the HTML file until the suite is finished.
When the project is fully finished and implemented, I want to run the tests outside of work hours for various reasons.
Therefore what I want to achieve is a mobile application where I can log in and view my tests progress.
To achieve this ( well from the plan I have taught up, someone else might be able to point me in a better direction ) I plan on finding a way to host results on a webserver which can then be accessed by the mobile application and convert these results into something viewable on the front end of the mobile application. The time accucary might not be a 100% with this method as the time it will take from the results to go from TestNG to the server to the mobile application but once its within reason it should be OK.
So the question is how can I store a live feed of my TestNG results on a webserver? Or even locally at the moment just for testing purposes.
Thanks.
I would log your results to the db of your choice and then create a mobile friendly webpage that queries the db and summarizes the run.
If that's too much work, can you not just post your HTML file to a webserver that you have access to from your mobile device?

Auto Provisioning the IOS application in Installrapp.com

Basically, I need to update below screen shot details for every application generated or every build occurs in Installr app. I thoroughly checked API there is no method to help the above scenario.
I need to auto Provisioning the IOS application for each Build.
Now I am trying to accomplish that above task using Java, Jsoup web Scraping Technic . Please Let us know if the task is not possible to using above techs stack also suggest me any other JS to full fill the requirement.
I can see two options for you:
Option 1: Stay with your current techs stack...
Fire up the network tab in the developer toolbar of your favorite browser.
Play the scenario manually in your browser and carefully study the HTTP exchanges between your browser and the server.
Once you have understand the exchanges made, reproduce them with Jsoup in your Java code.
Option 2: Change your techs stack
I suggest you to try one the tools below:
Selenium
ui4j
Both handle Javascript and will facilitate the automation of your scenario.
They will automatically determine the appropriate exchanges to do.

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