I would to ask about html2image, i have some codes like this
import gui.ava.html.image.generator.HtmlImageGenerator;
import java.io.File;
public class html2image {
public static void main(String[] args) {
HtmlImageGenerator imageGenerator = new HtmlImageGenerator();
imageGenerator.loadHtml("<b>Hello World!</b> Please goto <a title=\"Goto Google\" href=\"http://www.google.com\">Google</a>.");
imageGenerator.saveAsImage("hello-world.png");
imageGenerator.saveAsHtmlWithMap("hello-world.html", "hello-world.png");
}
}
But seems like after i call this java, its not appear any image or output image, maybe i miss some configuration, anyone can help ?
Try to give the absolute path in imageGenerator.saveAsImage as otherwise the file will be generated in the working directory.
Related
We are trying cucumber serenity framework for end to end tests. I am fairly new the technology and I tired this simple code below.
actor.attemptsTo(Enter.theValue(path).into(Upload));
where path is the location of file i am trying to upload using browser's upload widget.Has anyone ever managed to perform actions like this using serenity screen play pattern.
Its really making us think of giving up serenity and just use cucumber-selenium framework as I can easily perform this using Upload.sendkeys(path);
Any help is much appreciated. Thanks in advance.
AS requested: Listing Steps:
public class ListingSteps
{
#Before
public void set_the_stage() {
OnStage.setTheStage(new OnlineCast());
}
#Given("^(.*) is able to click import products$") public void userIsAbleToClick(String actorName) throws Throwable
{
theActorCalled(actorName).wasAbleTo(Start.theApplication());
}
#When("^s?he imports a single item successfully$") public void heImportsASingleItemSuccessfully() throws Throwable
{
theActorInTheSpotlight().attemptsTo(Import.spreadsheet());
}
#Then("^(.*) are listed on ebay and amazon with all the right information$") public void itemsAreListedOnEbayAndAmazonWithAllTheRightInformation(String actorName, String SKU)
throws Throwable
{
//pending
}
Ignore then for now as its work in progress.
Import class:
public class Import implements Task
{
protected String path =
"C:\\somePathToFile\\populated_excel.xlsx";
public static Import spreadsheet()
{
return instrumented(Import.class);
}
#Override public <T extends Actor> void performAs(T actorName)
{
actorName.attemptsTo(Click.on(Products.ProductsScreen));
actorName.attemptsTo(Click.on(Products.Upload));
actorName.attemptsTo(Enter.theValue(path).into(Browse).thenHit(Keys.RETURN));//this is the line which is giving errors
actorName.attemptsTo(Click.on(Products.UploadButton));
}
}
Target Browse
public class Products
{
public static Target Browse = Target.the("browse file").locatedBy("//input[#type='file']");
}
Did you try removing these lines?
actorName.attemptsTo(Click.on(Products.ProductsScreen));
actorName.attemptsTo(Click.on(Products.Upload));
You don't need to open the upload file component, only write the file path directly to the input file element and perform the submit.
The way I managed to get this working was by using the FileToUpload class:
import net.thucydides.core.pages.components.FileToUpload;
FileToUpload fileToUpload = new FileToUpload(driver, fileName);
fileToUpload.fromLocalMachine().to(webElement);
I got this working with a simple:
import java.nio.file.*;
Path data = null;
try {
data = Paths.get(ClassLoader.getSystemResource(file).toURI());
} catch (URISyntaxException ignore) {}
ACTOR.attemptsTo(Upload.theFile(data).to(target));
file is an actual file that exists on your classpath, in src/test/resources if you have a Maven project.
target is something like:
Target.the("Image upload").located(By.xpath("//input[#type='file']"));
I cannot figure out what I am doing wrong here. I have tried all sorts of things, including absolute paths, relative, enabling logging (which also doesnt seem to be working, using Main, using DefaultCamelContext, adding threadsleep, but I cannot get camel to move a file from one folder to another.
Here is my code:
package scratchpad;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.dataformat.beanio.BeanIODataFormat;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.main.Main;
import org.apache.camel.spi.DataFormat;
public class CamelMain {
private static Main main;
public static void main(String[] args) throws Exception {
main = new Main();
main.addRouteBuilder( new RouteBuilder() {
#Override
public void configure() throws Exception {
// DataFormat format = new BeanIODataFormat(
// "org/apache/camel/dataformat/beanio/mappings.xml",
// "orderFile");
System.out.println("starting route");
// a route which uses the bean io data format to format a CSV data
// to java objects
from("file://input?noop=true&startingDirectoryMustExist=true")
.to("file://output");
}
});
//main.run();
main.start();
Thread.sleep(5000);
main.stop();
}
}
Can someone spot anything wrong with the above?
Thanks
You can for example read from the free chapter 1 for the Camel in Action book, as it has a file copied example it covers from top to bottom.
The pdf can be downloaded here: http://manning.com/ibsen/
Opening files in java seems a bit tricky -- for .txt files one must use a File object in conjunction with a Scanner or BufferedReader object -- for image IO, one must use an ImageIcon class -- and if one is to literally open a .txt document (akin to double-clicking the application) from java, this code seems to work:
import java.io.*;
public class LiterallyOpenFile {
public static void main(String[] args) throws IOException {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("notepad Text.txt");
}
}
I'm not positive, but I think other file-types / names can be substituted in the parenthesis after exec -- anyway, I plan on opening certain files in a JFileChooser when the user clicks on a file to open (when the user clicks on a file, the path to the file can be obtained with the getSelectedFile() method). Though I'm more specifically looking to be able to open an Arduino file in the Arduino IDE from a java program, like a simulated double-click.. perhaps something like this?
import java.io.*;
public class LiterallyOpenFile {
public static void main(String[] args) throws IOException {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("Arduino C:\\Arduino\\fibonacci_light\\fibonacci_light.ino");
}
}
A point in the right direction would be appreciated.
Have you tried this? If there is a registered program for your file in windows, this should work. (i.e. the default application should open the file)
Desktop desktop = Desktop.getDesktop();
desktop.open(file);
The file parameter is a File object.
Link to API
Link to use cases and implementation example of the Desktop class
This is what I do in my projects using java.awt.Desktop
import java.awt.Desktop;
import java.io.IOException;
import java.io.File;
public class Main
{
public static void main(String[] args) {
try {
Desktop.getDesktop().open(new File("C:\\Users\\Hamza\\Desktop\\image.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
I have written a grammar that allows the user to input a relative path. (e.g. "../../temp/out/path"
May aim is to get the absolute path based on the input from the user, and the absolute path of the current working directory so that I can also check if the input path is valid or not.
Is there libraries or built in functions that I can use to get the absolute path?
Something similar to C's _getcwd() function.
Yes, Java has a File class. You can create one by calling this constructor which takes a String. Then you can call getAbsolutePath() on it. You can call it like this:
package com.sandbox;
import java.io.File;
public class Sandbox {
public static void main(String[] args) {
File file = new File("relative path");
String absolutePathString = file.getAbsolutePath();
}
}
This will print a complete absolute path from where your application has initialized.
public class JavaApplication1 {
public static void main(String[] args) {
System.out.println("Working Directory = " +System.getProperty("user.dir"));
}
}
Alrighty, so I'm working on making a .jar for a client for a little game and I know how to use everything and have done this before, on windows, now i'm on a mac. This shouldn't make a difference but incase you wanted to know, there you go.
Now, I have a folder in eclipse named client, now normally the client.java is the main class but there is another named EGUI, this has the "public static void main(String[] args)", but in my client.java file, it also has a method like this:
public static final void main(String args[])
{
try
{
anInt957 = 0;
anInt958 = 0;
method52(false);//highmem
aBoolean959 = true;//members
signlink.storeid = 32;
signlink.startpriv(InetAddress.getLocalHost());
client client1 = new client();
client1.method1(503, false, 765);
setserver(args[0], "5555");
return;
}
catch(Exception exception)
{
return;
}
}
I guess my question is, does the "final" make it the main file? Or would it still be the EGUI, which looks like this:
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class EGUI
{
public static void main(String args[])
{
client.main(new String[] {
"127.0.0.1", "127.0.0.1", "127.0.0.1"
});
}
}
So, what i'm asking for is, why is it that when I'm setting the main file to EGUI, it isnt working? the applet opens up, but I keep getting an "error connecting to server" message every time, when I run it through terminal by copying the run.bat info and pasting that, it works perfectly! Any help is greatly appreciated!
public static void main(String args[]) means you can execute the class from the commandline. The final keyword means the method cannot be overridden by a sub class.
In your case this does not make it the jar's main execution class. The main class is set in META-INF/MANIFEST.MF. Normally it should have a line:
Main-Class: classname
but then with the actual class.
So open the jar with a zip program, and check MANIFEST.MF.
Your client.java has a main method, for testing purposes I suppose.