0

I need to take snapshot of webpage and for that I am using selenium RC (this is good choice right ? )with eclipse for java language . I am using it as JUnit test case . Here is my code.

package com.example.tests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

@SuppressWarnings("deprecation")
public class mainClassTest extends SeleneseTestCase {
    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.gmail.com/");
        //water= new DefaultSelenium("localhost", 4444, "*firefox", "http://www.gmail.com/");
        selenium.start();

    }

    @Test
    public void testFinalSelenium() throws Exception {


        selenium.windowMaximize(); 

        selenium.open("/");
        selenium.waitForPageToLoad("30000");


        System.out.println("laoded\n");
    //  selenium.wait();
         selenium.captureScreenshot("C:\\test\\simpleQuora.png");
         selenium.captureEntirePageScreenshot("C:\\test\\CompleteQuora.png", "");
    }

    @After
    public void tearDown() throws Exception {

        selenium.stop();

    }


}

And it's working fine but If i have to take snapshot of multiple URLs, then what are the ways to do that ? Can we do it without using it as JUnit test case and using selenium in main function ?

Because if I try to run this code :

package com.example.tests;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class MainClass {


    void func(String url, String file)
    {
        Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", url);
        selenium.start();

        selenium.windowMaximize(); 

        selenium.open("/");
        selenium.waitForPageToLoad("30000");


        System.out.println("laoded\n");
    //  selenium.wait();
        String file1= "C:\\test\\"+file+".png";
        String file2= "C:\\test\\"+file+"2.png";
        selenium.captureScreenshot(file1);
        selenium.captureEntirePageScreenshot(file2, "");

        selenium.stop();

    }


    public static void main(String[] args)
    {

        MainClass demo = new MainClass();

        demo.func("www.facebook.com","face"); 

        //demo.func("www.reddit.com","reddit"); 

    }
}

I got this error.(Although I have started server from cmd).

1 Answers1

1
    demo.func("www.facebook.com","face"); 

changes to

    demo.func("http://www.facebook.com","face"); 
andy.wen
  • 51
  • 1