Can not find Image path in Upload document script using Sikuli with webdriver - selenium-webdriver

Can not find Image path in Upload document script using Sikuli with selenium web driver, I am using latest Sikuli jar. I am getting following Error while running followed code snippet:
Screen src = new Screen();
Match addFile= src.find("C:\\Users\\Inknopwledge\\Desktop\\TestSikuli\\Capture.PNG");
FindFailed: can not find C:\Users\Inknopwledge\Desktop\Sikuli\Capture.PNG on the screen.
Line ?, in File ?
at org.sikuli.script.Region.handleFindFailed(Region.java:420)
at org.sikuli.script.Region.wait(Region.java:511)
at org.sikuli.script.Region.find(Region.java:381)
at pagefactory.profile_section.ResearchandExp_pageFact.click_Attach_Documents(ResearchandExp_pageFact.java:195)
at TestCase.ResearchandExpertise_TC.attach_Document_to_Research(ResearchandExpertise_TC.java:311)
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:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Unable to upload document [Ljava.lang.StackTraceElement;#17c395e

"As per your statement Exception is : FindFailed: can not find C:\Users\Inknopwledge\Desktop\Sikuli\Capture.PNG on the screen.
This exception occurs when image with given path not found on screen within 3 second (default auto wait timeout for find operation in sikuli is 3 seconds) with default simillarity 0.7
You can make wait to load image then use find command or use:
Screen s = new Screen();
Pattern p = new Pattern ("img path/path").similar( (float) 0.7);
if (s.exists(p , 7) != null) {
Match match = s.getLastMatch();
}
Above command wait for 7 sec for image to appear on screen. Change your similarity percentage to get match. you image may be different form that displayed on app.

I had the same issue when using this in conjunction with Appium Driver. I realized that the image that I was snipping using my mac was not the one Sikuli could find. There are two resolutions then:
Download and install Sikuli IDE and use that for the snaps
Use the following code:
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;
public void capture (String path){
Screen screen = new Screen();
screen.userCapture().save(path);
}
This would basically freeze the screen and allow you to snip the image and store it in the path which you mention. You can use an IDE to run this or create an executable jar file to run it from command line

Related

main class in fat jar fails when using static factory method, but works fine in IDE

I have a small project that i'm using shadowJar to create a fatjar to run from command line..
the main class entry point gets ref to class in the project using static factory method like this
static void main (args){
MessageSystemClient mclient = MessagePlatformFactoryProducer.getFactory().getMessagePlatformInstance("WLS")
println "howdi "....
}
when i run the fat jar at the command line i get an error like so
PS D:\Intellij-projects\message-platform-client\build\libs> java -jar message-platform-client-1.0-SNAPSHOT.jar --send "hello" -r
Exception in thread "main" java.io.FileNotFoundException: file:\D:\Intellij-projects\message-platform-client\build\libs\message-platform-client-1.0-SNAPSHOT.jar!\ApplicationConfig.groovy (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at groovy.util.CharsetToolkit.<init>(CharsetToolkit.java:77)
at org.codehaus.groovy.runtime.ResourceGroovyMethods.newReader(ResourceGroovyMethods.java:1741)
at org.codehaus.groovy.runtime.ResourceGroovyMethods.getText(ResourceGroovyMethods.java:592)
at org.codehaus.groovy.runtime.dgm$1013.doMethodInvoke(Unknown Source)
at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.doMethodInvoke(GeneratedMetaMethod.java:83)
at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty.java:76)
at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:63)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:298)
at com.softwood.implementation.MessagePlatformFactory.getMessagePlatformInstance(MessagePlatformFactory.groovy:29)
at com.softwood.client.AbstractMessagePlatformFactory$getMessagePlatformInstance.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127)
at com.softwood.cli.Launcher.main(Launcher.groovy:40)
however if i comment out the static factory call - and regenerate then the fat jar runs ok and prints the howdi to the console.
if i uncomment the factory lookup again, and just run the Launcher class in the IDE the code works fine with no problems
so why is it failing as a fatjar, but works as ordinary project?. secondly assuming its something to do with fatjar zip approach - how do i overcome this ?
I had a earlier version of the project that just directly called static methods on project classes, and that works fine as a fatjar - so the problem is with the static factory behavior inside a fatjar .
i tried to load the classes using
Launcher.getClass().getClassLoader().loadClass ("<various factory classes etc>")
the classes would load ok - but the factory call itself still breaks as shown above in stack trace
Can any one help me over this problem please?
Found it - in my factory methods I was doing a call like this to load a configFile:
File configFile = new File(classLoader.getResource("ApplicationConfig.groovy")?.getFile())
However as per related link, this won't work in a fat jar as there's no full file system in the jar.
What you have to do is use line like:
InputStream configStream = classLoader.getResourceAsStream("ApplicationConfig.groovy")
as this will work in the jar, and test if stream is null (can't find your resource in the fatjar) or you get the stream itself which you can read the text from the file.
Took a while, but now back on I think.

Flink: Could not find a suitable table factory for 'org.apache.flink.table.factories.DeserializationSchemaFactory' in the classpath

I am using flink's table api, I receive data from kafka, then register it as
a table, then I use sql statement to process, and finally convert the result
back to a stream, write to a directory, the code looks like this:
def main(args: Array[String]): Unit = {
val sEnv = StreamExecutionEnvironment.getExecutionEnvironment
sEnv.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)
val tEnv = TableEnvironment.getTableEnvironment(sEnv)
tEnv.connect(
new Kafka()
.version("0.11")
.topic("user")
.startFromEarliest()
.property("zookeeper.connect", "")
.property("bootstrap.servers", "")
)
.withFormat(
new Json()
.failOnMissingField(false)
.deriveSchema() //使用表的 schema
)
.withSchema(
new Schema()
.field("username_skey", Types.STRING)
)
.inAppendMode()
.registerTableSource("user")
val userTest: Table = tEnv.sqlQuery(
"""
select ** form ** join **"".stripMargin)
val endStream = tEnv.toRetractStream[Row](userTest)
endStream.writeAsText("/tmp/sqlres",WriteMode.OVERWRITE)
sEnv.execute("Test_New_Sign_Student")
}
I was successful in the local test, but when I submit the following command
in the cluster, I get the following error:
=======================================================
org.apache.flink.client.program.ProgramInvocationException: The main method
caused an error.
at
org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:546)
at
org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:421)
at
org.apache.flink.client.program.ClusterClient.run(ClusterClient.java:426)
at
org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:804)
at
org.apache.flink.client.cli.CliFrontend.runProgram(CliFrontend.java:280)
at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:215)
at
org.apache.flink.client.cli.CliFrontend.parseParameters(CliFrontend.java:1044)
at
org.apache.flink.client.cli.CliFrontend.lambda$main$11(CliFrontend.java:1120)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at
org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1692)
at
org.apache.flink.runtime.security.HadoopSecurityContext.runSecured(HadoopSecurityContext.java:41)
at
org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1120)
Caused by: org.apache.flink.table.api.NoMatchingTableFactoryException: Could
not find a suitable table factory for
'org.apache.flink.table.factories.DeserializationSchemaFactory' in
the classpath.
Reason: No factory implements
'org.apache.flink.table.factories.DeserializationSchemaFactory'.
The following properties are requested:
connector.properties.0.key=zookeeper.connect
....
schema.9.name=roles
schema.9.type=VARCHAR
update-mode=append
The following factories have been considered:
org.apache.flink.table.sources.CsvBatchTableSourceFactory
org.apache.flink.table.sources.CsvAppendTableSourceFactory
org.apache.flink.table.sinks.CsvBatchTableSinkFactory
org.apache.flink.table.sinks.CsvAppendTableSinkFactory
org.apache.flink.streaming.connectors.kafka.Kafka011TableSourceSinkFactory
at
org.apache.flink.table.factories.TableFactoryService$.filterByFactoryClass(TableFactoryService.scala:176)
at
org.apache.flink.table.factories.TableFactoryService$.findInternal(TableFactoryService.scala:125)
at
org.apache.flink.table.factories.TableFactoryService$.find(TableFactoryService.scala:100)
at
org.apache.flink.table.factories.TableFactoryService.find(TableFactoryService.scala)
at
org.apache.flink.streaming.connectors.kafka.KafkaTableSourceSinkFactoryBase.getDeserializationSchema(KafkaTableSourceSinkFactoryBase.java:259)
at
org.apache.flink.streaming.connectors.kafka.KafkaTableSourceSinkFactoryBase.createStreamTableSource(KafkaTableSourceSinkFactoryBase.java:144)
at
org.apache.flink.table.factories.TableFactoryUtil$.findAndCreateTableSource(TableFactoryUtil.scala:50)
at
org.apache.flink.table.descriptors.ConnectTableDescriptor.registerTableSource(ConnectTableDescriptor.scala:44)
at
org.clay.test.Test_New_Sign_Student$.main(Test_New_Sign_Student.scala:64)
at
org.clay.test.Test_New_Sign_Student.main(Test_New_Sign_Student.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:529)
===================================
Can someone tell me what caused this? I am very confused about this........
if you are using maven-shade-plugin, make sure SPI transformer is placed.
Flink uses java Service Provider to discover Source/Sink connector.
Without this transformer, you will 100% encoutner "org.apache.flink.table.api.NoMatchingTableFactoryException: Could
not find a suitable table factory", which happened on me.
https://ci.apache.org/projects/flink/flink-docs-release-1.9/dev/table/connect.html#update-mode
flink officially points out this, search "SPI" on this page
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
You have to add the JAR dependencies of the connectors (Kafka) and formats (JSON) that you are using to the classpath of your program, i.e., either build a fat JAR that includes them or provide them to the classpath of the Flink cluster by copying them in the ./lib folder.
Check the Flink documentation for links to download the respective dependencies.
I have the met the same problem, just add parameters --connector.type kafka when you run your application will solve this. see enter link description here

NullPointer on Bitmap.getWidth in Codenameone Android app

I have an app created in CodenameOne running on Android that is throwing NullPinterExpections after trying to scale too many images. I've used CacheMap to help the situation but still get the issue after loading too many images.
Here is my code that throws the issue, from within InfiniteContainer fetchComponents
Image i = (Image) MoveService.getInstance().getImage(thumbnail_url);
if (i == null) {
i = theme.getImage(move.getThumbnail_url());
if (i != null) {
i = i.fill(width+20, (width / 2) * 3);
MoveService.getInstance().putImage(move.getThumbnail_url(), i);
}
}
And here is what I get from the logs:
[EDT] 0:8:57,596 - Exception: java.lang.NullPointerException - Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:748)
at com.codename1.impl.android.c.a(AndroidImplementation.java:1688)
at com.codename1.k.s.c(Image.java:1008)
at com.codename1.k.s.c_(Image.java:954)
at com.codename1.k.s.b(Image.java:919)
at com.codename1.impl.android.c$8.a(AndroidImplementation.java:6216)
at com.codename1.k.n.a(EncodedImage.java:627)
at com.codename1.k.n.b(EncodedImage.java:654)
at com.codename1.k.s.e(Image.java:903)
at com.codename1.k.s.f(Image.java:974)
at com.altitude.studios.polebible.e$b.<init>(Unknown Source)
at com.altitude.studios.polebible.e$16.a(Unknown Source)
at com.codename1.k.u.m(InfiniteContainer.java:143)
at com.codename1.k.u$5.run(InfiniteContainer.java:172)
at com.codename1.k.m.l(Display.java:1154)
at com.codename1.k.m.j(Display.java:1098)
at com.codename1.k.m.i(Display.java:999)
at com.codename1.k.ad.run(RunnableWrapper.java:120)
at com.codename1.impl.b$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:818)
This can happen if an image went thru the wrong pipeline and the underlying native image is gone. If the image is a font image or a similar "exotic" image try converting it to a regular image using toEncodedImage() or similar method.
It can also happen if you explicitly invoked dispose() on an image.

FitNesse Error while executing Sikuli code

I am trying to execute sikuli code through FitNesse.
the following error is displayed.
Could not detect death of command line test runner.
java.lang.IllegalThreadStateException: process has not exited
at java.lang.ProcessImpl.exitValue(Native Method)
at fitnesse.testsystems.CommandRunner.join(CommandRunner.java:86)
at fitnesse.testsystems.slim.SlimTestSystem.bye(SlimTestSystem.java:117)
Same code is working through eclipseIde but while running Test from FitNesse
Thanks in Advance
Adding more information on the observed issue:
I have integrated Sikuli code for upload a file and following is the Sikuli code for upload:
public void uploadSikiuliCode(String image){
String target ="C:/Users/TestQA/Desktop/TextBox.png";
Screen s = new Screen();
try{
s.click(target,0);
s.type(image, 0);
waitForPageLoad(3);
s.click("C:/Users/TestQA/Desktop/Open.png",0);
}
catch(Exception e){
e.printStackTrace();
}
}
I have executed and able to upload file using Eclipse IDE
I have integrated the same to FitNesse and executed it was working fine till it enters into the Sikuli (upload) method
After entering into the method while executing the
Screen s = New Screen ()
The following error is displayed
Could not detect death of command line test runner.java.lang.IllegalThreadStateException: process has not exited
at java.lang.ProcessImpl.exitValue(Native Method)
at fitnesse.testsystems.CommandRunner.join(CommandRunner.java:86)
at fitnesse.testsystems.slim.SlimTestSystem.bye(SlimTestSystem.java:117)

Could not start Selenium session: You may not start more than one session at a time

this is a configuration error , when trying to configure selenium with eclipse , what i read in a couple of websites is that , adding a dependency to maven would do , but nothing worked , i have been spending a lot of hours/day , even modified the system property , to add firefox profile into it , but nothing worked . looks like i am the first one on this earth to get this error
thankyou
pasting a stack trace , for your reference
java.lang.RuntimeException: Could not start Selenium session: You may not start more than one session at a time
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:90)
at TestAddVisitor.setUp(TestAddVisitor.java:36)
at junit.framework.TestCase.runBare(TestCase.java:132)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:228)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.thoughtworks.selenium.SeleniumException: You may not start more than one session at a time
at org.openqa.selenium.WebDriverCommandProcessor.start(WebDriverCommandProcessor.java:217)
at org.openqa.selenium.WebDriverCommandProcessor.start(WebDriverCommandProcessor.java:208)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:82)
... 16 more
I guess this is not a configuration error. If my understanding is correct you are are creating WebDriver object and then creating DefaultSelenium / Selenium object with it and then starting the selenium session.
then -- don't use DefaultSelenium.start() method.
Code should be like this:
DefaultSelenium ds = new DefaultSelenium(
new WebDriverCommandProcessor("baseURL",new FirefoxDriver()));
// ds.start(); -- do not do this
ds.open("/");
This might help you.
Did you take a look at http://seleniumhq.org/docs/03_webdriver.html#webdriver-backed-selenium-rc? sudarsan in the previous answer is right: don't do selenium.start.
If you wonder that the JUnit Code from the Selenium IDE throughs this exception, see http://osdir.com/ml/selenium-users/2011-07/msg02107.html

Resources