Wait function not working to Pause Hybrid script execution kindly guide how to overcome this issue | Selenium Forum
H
Harsh Posted on 03/05/2019

Not able to Pause my Hybrid script for few seconds using Wait function and getting ‘java.lang.reflect.InvocationTargetException’ exception

Below is Wait function written in GenericKeywords :

public void wait(int time){
try{
Thread.sleep(time*1000);
}catch (InterruptedException e){
e.printStackTrace();
}
}

Below is Console log:

[TestNG] Running:

  C:\Users\hbhardwaj4\AppData\Local\Temp\testng-eclipse-1055332000\testng-customsuite.xml

 

****NewAppTRVTest

C:\Users\hbhardwaj4\OneDrive - DXC Production\Final Consolidated\Profesional\Professional_Notes\Selenium\workspace\DHAApp\Files\DHASuiteOne.xlsx

Inside Data Provide newappTRVTest

Row number of the test is 5

Total Cols - 4

Total Rows 1

{ApplicationType=Temporary Residence Visa, ApplicationSubType=Corporate Account, Runmode=Y, Browser=Chrome}

-----------------------------

C:\Users\hbhardwaj4\OneDrive - DXC Production\Final Consolidated\Profesional\Professional_Notes\Selenium\Hybrid\reports\Fri_May_03_06_29_53_IST_2019//SIT Execution Status.html

Running Login test

Rows 12

Starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 8635

Only local connections are allowed.

Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

May 03, 2019 6:30:01 AM org.openqa.selenium.remote.ProtocolHandshake createSession

INFO: Detected dialect: OSS

log4j:WARN No appenders could be found for logger (freemarker.cache).

log4j:WARN Please initialize the log4j system properly.

FAILED: newappTRVTest({ApplicationType=Temporary Residence Visa, ApplicationSubType=Corporate Account, Runmode=Y, Browser=Chrome})

java.lang.reflect.InvocationTargetException

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

      at java.lang.reflect.Method.invoke(Unknown Source)

      at com.vfs.pro.hybrid.driver.DriverScript.executeKeywords(DriverScript.java:66)

      at com.vfs.pro.testcases.dhasuiteone.NewAppTRVTest.newappTRVTest(NewAppTRVTest.java:28)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

      at java.lang.reflect.Method.invoke(Unknown Source)

      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)

      at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)

      at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)

      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)

      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)

      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)

      at org.testng.TestRunner.privateRun(TestRunner.java:782)

      at org.testng.TestRunner.run(TestRunner.java:632)

      at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)

      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)

      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)

      at org.testng.SuiteRunner.run(SuiteRunner.java:268)

      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)

      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)

      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)

      at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)

      at org.testng.TestNG.run(TestNG.java:1064)

      at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)

      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)

      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

Caused by: java.lang.IllegalMonitorStateException

      at java.lang.Object.wait(Native Method)

      at java.lang.Object.wait(Unknown Source)

      ... 30 more

 

 

===============================================

    Default test

    Tests run: 1, Failures: 1, Skips: 0

===============================================

 

 

===============================================

Default suite

Total tests run: 1, Failures: 1, Skips: 0

===============================================

 

[TestNG] Time taken by org.testng.reporters.EmailableReporter2@79698539: 66 ms

[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 91 ms

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@38082d64: 21 ms

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@2f7a2457: 313 ms

[TestNG] Time taken by org.testng.reporters.XMLReporter@668bc3d5: 23 ms

[TestNG] Time taken by org.testng.reporters.jq.Main@1554909b: 129 ms

 


A
Ashish Thakur Replied on 03/05/2019

Did you try debugging the code?

The error is possibly at DriverScript.java line number 66 or NewAppTRVTest.java line number 28


H
Harsh Replied on 05/05/2019

Hi Ashsish, I Dubug my code and identified InterruptedException as 'public final void java.lang.Object.wait() throws java.lang.InterruptedException' displaying for Wait function.

Kindly suggest where I did mistake and how to over come this. Attching screenshot of exception.


A
Ashish Thakur Replied on 06/05/2019

Invocation Targer Exception for ReflectionAPI, this is caused due to the conflict in Function name and keyword you are using. Make sure the case and spelling, bith are in the samme format.


H
Harsh Replied on 09/05/2019

Hi Ashish, i checked my code, Function and Keywords but not able to identify any root couse of the issue. I am badly stuck on this point since last week.

Kindly suggest your suitable time when can i share screen with you.


H
Harsh Replied on 15/05/2019

Hi Ashish,

On execution of code, I am getting exception as 'java.lang.IllegalMonitorStateException at java.lang.Object.wait(Native Method).

Do we need to use Notify() in wait function written in generic keywords?


H
Harsh Replied on 15/05/2019

Hi Ashish,

Kindly find details of line number 66 of Driver script and line number 28 of the test case.
           //Reflections API in JAVA
            Method method;
                             method=app.getClass().getMethod(keyword);
Line 66:               method.invoke(app);

**************************************************************************

Line 28:               ds.executeKeywords(testName, xls, data);


H
Harsh Replied on 18/05/2019

Hi Ashish, I sent you zipped project through mail, kindly update if you get the issue.


A
Ashish Thakur Replied on 22/05/2019

Is the issue resolved now?


R
Raj Kishore Replied on 25/06/2019

Hi Harsh,

How did you resolved this '‘java.lang.reflect.InvocationTargetException’' issue? I got stuck in the similar situation as i am unable to invoke the firefox browser with openBrowser() method. Please let me know how you had resolved this issue?

Thank you,

Regards,

Kishore


H
Harsh Replied on 26/06/2019

Hi Kishor,

No need to invoke openBrowser() method. Refer second method from below link:

http://www.automationtestinghub.com/selenium-chromedriver/

Do let me know if you are facing issue.

Regards

Harsh


A
Ashish Thakur Replied on 26/06/2019

Kishore, there are multiple factors affecting this. Reflect API doesn't support method names which demand a parameter to be passed as an argument.

In addition to this, the case of Keyword name and method name needs to be exactly the same.


H
Harsh Replied on 17/07/2019

Hi Ashish,
 
I am not able to see my query logged into the Selenium Forum. Kindly look into the issue.

Regards
Harsh


A
Ashish Thakur Replied on 18/07/2019

Are you having access to other tools as well? if yes, please cross-check that you may not have raised in the wrong tool.

Additionally, When was the query raised? Share the link of the query if you have that.

You can raise a new query as well.


H
Harsh Replied on 18/07/2019

Yes Ashish, I have access of Selenium and JMeter tools. But I raised query for Selenium in correct tool.
I Tried to raise query at around 4AM (IST) on 13th July and 10AM on 17th July, but my query was not reflecting in the portal.


A
Ashish Thakur Replied on 19/07/2019

Please raise the query again and mail us the link at abhishek@whizdomtrainings.com