0

I have to build a java project which has to complete the following use cases:

  1. get the url from user: for this need to show a alert window to the user to get the url.If user clicked on Cancel , close the programe.

  2. Open the entered url in browser: Once the user has entered the url and clicked on Ok, the browser should show that url.

  3. Let the user close the browser window

  4. Once the user closes the browser window go back to prompt window to ask the user do you want to continue or quit. If contiue then again open the window to enter url else close.

How can I achieve all the above steps in java and selenium? Please help. EDIT: Adding the code that I have so far.

    Scanner reader=new Scanner(System.in);
    System.out.println("Enter the endpoint to hit");
    String url=reader.next();  

    String classLoader = getClass().getClassLoader().getResource("file.txt").getFile();
    Scanner in =new Scanner(new File(classLoader));

    while(in.hasNext()){
        String line=in.nextLine();
        String formedUrl=url+line;
        BaseSeleniumSetup.setupChromeDriver(formedUrl);
    }

    in.close();

 public class BaseSeleniumSetup {
    public static void setupChromeDriver(String url) throws InterruptedException {
        WebDriver driver= new ChromeDriver();
        driver.get(url);
        Thread.sleep(2000);
        driver.quit();
    }
}
7
  • 1
    You can do it by writing some code. If you have specific question come back here, with the code you are stuck with, and you will get help. No one here is going to do this for you. Commented May 18, 2017 at 4:42
  • @worrynerd Can you consider showing us your work please? Thanks Commented May 18, 2017 at 7:01
  • @Dev: Added code that I have so far. Commented May 18, 2017 at 16:36
  • Your code looks great :) now where do you want me to help you from Selenium point of view? Thanks Commented May 18, 2017 at 17:09
  • These are my open items : 1.right now I run my code on thru the java main() I have to present it and just running thru the main dsnt show good.I want it to make it more presentable. 2: once the browser window open I want the user to close the window and then again prompt if you want to conitue or exit. Commented May 18, 2017 at 17:44

1 Answer 1

1

You can use library import javax.swing.JOptionPane; and the following steps

String url = JOptionPane.showInputDialog(null,"Enter URL"); //To create window
WebDriver driver =new ChromeDriver(); //To open browser
driver.get(url); // To open url in browser
Sign up to request clarification or add additional context in comments.

2 Comments

Great @Rabia Asif: this works and I am able to get one use case done.
Can you please help me in the other use cases which I am unable to implement : These are my open items : 1.right now I run my code on thru the java main() I have to present it and just running thru the main dsnt show good.I want it to make it more presentable. 2: once the browser window open I want the user to close the window and then again prompt if you want to conitue or exit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.