Getting exception while executing the java Main method

529 views
Skip to first unread message

Suraj Ray

unread,
Apr 29, 2015, 2:09:20 PM4/29/15
to browserm...@googlegroups.com
Need help on below item.

I tried setting up the BMP but failing when I execute Java main method with below exception

Caused by: java.lang.ClassNotFoundException: net.lightbody.bmp.BrowserMobProxy
at java.net.URLClassLoader$1.run(Unknown Source)

I am able to compile the java code properly and I can see the jars in the maven dependency folder but as soon as I try to run the program, encountering the above eexception.

I only have one entry to my POM
<dependency>
         <groupId>net.lightbody.bmp</groupId>
         <artifactId>browsermob-core-littleproxy</artifactId>
         <version>2.1.0-beta-1-SNAPSHOT</version>
         <scope>test</scope>
     </dependency>

And the code m trying to run is as below

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BrowserMobProxy server = new BrowserMobProxyServer();
   
        server.start(0);
    int port = server.getPort();
 // get the Selenium proxy object
    Proxy proxy = ClientUtil.createSeleniumProxy(server);

    // configure it as a desired capability
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, proxy);
           
           // start the browser up
    WebDriver driver = new FirefoxDriver(capabilities);

    // create a new HAR with the label "yahoo.com"
    server.newHar("yahoo.com");

    // open yahoo.com
    driver.get("http://yahoo.com");

    // get the HAR data
    Har har = server.getHar();
         
 }

Suraj Ray

unread,
Apr 29, 2015, 3:25:40 PM4/29/15
to browserm...@googlegroups.com
I think I found the issue, it is a maven project and I was writing a Java Main method because of which it was unable to find the correct class during runtime.
I changed it to testNG test and it works now.

Regards,
Suraj

Krishnan Mahadevan

unread,
Apr 30, 2015, 12:19:21 AM4/30/15
to browserm...@googlegroups.com
Hmmm... That's an awkward fix to be honest.
The build tool should work the same way irrespective of how your code is being executed [ either via a Test runner such as TestNG/JUnit or via the conventional public static void main() method ]

So I don't think that is a problem here.

The problem I am guessing is the scope you have defined : Your scope reads as "test" which basically means that the BMP libraries are only available for usage in classes that are under src/test/java.

The reason why you perhaps saw ClassNotFoundException was because your main() method may have resided in a class under src/main/java and your problem got fixed after you moved them to a TestNG test because tests normally reside under src/test/java


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--

---
You received this message because you are subscribed to the Google Groups "BrowserMob Proxy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to browsermob-pro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Suraj Ray

unread,
Apr 30, 2015, 2:09:55 AM4/30/15
to browserm...@googlegroups.com
Hi Krishnan,

You are absolutely correct. Thanks

Regards,
Suraj

Suraj Ray

unread,
Apr 30, 2015, 12:34:03 PM4/30/15
to browserm...@googlegroups.com
Code same as in my earlier mail....

ProxyServer server = new ProxyServer(8107);
         server.start();
         server.setCaptureHeaders(true);
         server.setCaptureContent(true);
         server.newHar("gooogle home page");
         DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(capabilities);
         driver.get("http://www.google.com");
         driver.findElement(By.id("lst-ib")).sendKeys("hello");
         driver.findElement(By.name("btnG")).click();
         Har har1 = server.getHar();
         System.out.println("HAR content is:   "+ har1);
         
         har1.writeTo(new File("har.json"));
         server.stop();
         driver.quit();

and the HAR I got is as below, is it correct??

log
Object
version
1.2
creator
Object
name
BrowserMob Proxy
version
2.0
comment
pages
Array [1]
0
Object
id
gooogle home page
startedDateTime
2015-04-30T16:46:32.402+05:30
title
pageTimings
Object
comment
comment
entries
Array [0]
comment

On Wed, Apr 29, 2015 at 11:39 PM, Suraj Ray <suraj...@gmail.com> wrote:

Suraj Ray

unread,
May 1, 2015, 3:20:51 PM5/1/15
to browserm...@googlegroups.com
I think the output is fine.
I have one doubt, how the proxyserver is to be setup in the automation framework?

From this I mean, are you integrating browsermobproxy at some listener level or at before suite level?

Regards,
Suraj
Reply all
Reply to author
Forward
0 new messages