I came across the following question asked in interviews which ask about controlling a web browser using a web service calls.
Implement the following 4 WebServices in the choice of your language.
startBrowser() -> Start the browser(User Input) and opens given URL(User Input)
stopBrowser()-> Kill the specified opened browser.
getLatestURL()-> Fetched last visited URL (Doesn’t matter browser is running or it’s closed)
deleteAllHistory()-> Delete all the data -> Browser History, cookies, cache, saved passwords, bookmarks etc.
https://www.geeksforgeeks.org/browserstack-mumbai-interview-experience-software-engineer/
Most of what I saw while trying to find answer to it ( on SO and other websites) was to use the main method to open a java framework based browser using java.awt and URL processing.
The above question demands opening a web browser using a web service call, which is possibly by hitting a rest service which opens and closes browser and does other operations mentioned in the question.
May I know how is it possible to interface a web browser (client side installed tool ) with a web service call ? Are there any special apis or annotations using REST. I am not able to understand the only part regarding interfacing web service call ( possibly using postman) with an application ( web browser) installed on client side.
CodePudding user response:
using java we can start browser
package test;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
public class Example {
public static void main(String[] args) throws IOException, URISyntaxException {
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URI("www.xyz.com"));
}
}
CodePudding user response:
You need a tool that can control browser opening and a tool that can control the browser itself. The former one is shell, the latter one is for example selenium: https://www.selenium.dev/ You can solve most of the upper with java and selenium I think. Here is an example of how you can use selenium to open browser: https://automationbyte.com/how-to-launch-firefox-browser-using-selenium/ As of the REST service it must run in the same OS you want to use to open the browser. There are already existing similar solutions like SauceLabs, maybe they use REST services in the background to control testing, who knows. https://saucelabs.com/