First steps with Selenium RC - java

I am trying to move the first steps in web scraping. I read about selenium and seems to me that it fit for what i am looking for. But i have some problems to start. I am following this tutorial selenium getting started and i am trying to compile the first example with my linux ubuntu. I have compiled in this way
javac -classpath selenium-server-standalone-2.20.0.jar Example.java
i have started selenium server with
java -jar selenium-server-standalone-2.20.0.jar
but i can't run Example. This way doesn't works
java Example
and this way too
java -classpath selenium-server-standalone-2.20.0.jar Example
I guess that the grammar is wrong, but where?

You need to include the current directory in the classpath like so:
java -cp .:selenium-server-standalone-2.20.0.jar Example
Also since you did not actually put the Example.java in org.openqa.selenium.example, you probably want to delete the package org.openqa.selenium.example in the first line of the source.

While writing code in Java a better approach would be using an IDE like Eclipse. Once you link the JARs and import them in your Java classes you can write your code quickly and efficiently.
On top of that, Eclipse has lot of plugins for testing software like Junit, TestNG's to help you create better test suites.
Not to mention a Java IDE is always helpful in debugging test code. Here is a tutorial on how to setup Eclipse with Selenium: link
Hope it helps.

Related

JMeter external JSR223 java edited in Intellij

I'd like to reach that point where I have a development environment with the following attributes:
JMeter tests consist of JSR 233 scripts mainly
JSR 233 scripts are written in Java
I can edit the java code in IntelliJ
the project is a maven project
So far I could do everything from the list above except IntelliJ support. So, I add a JSR 233 PreProcessor script to the test using JMeter GUI, I setup the script path. When I create the .java file and start to edit in Intellij following examples IntelliJ gets crazy, since the code is not enclosed in a class {}. As a result I can't leverage on IntelliJs capabilities and great support in java.
Is there any way to configure IntelliJ to support these script files?
I double checked how the example Java code is stored in the jmx file, and it is not enclosed in a class {}.
Why not Groovy? you might ask. The reason is that, when I made a mistake in groovy script it doesn't cause build failure, it will give me a runtime error. I consider this not effective enough, however groovy is plan C.
Plan B is all java code gets into an external jar and will be included in minimal groovy script.
I would really appreciate if you could help with answers or any articles probably answers my question.
Java scripting code is actually running Beanshell language
You have BeanShell Box plugin that support your requirement in Intellij
Adds a BeanShell toolbox allowing you to write snippets of both Java and BeanShell code.
Benshell file extension is .bsh usually

Robot framework +jenkins, testing java application

I'm working on CentOS 6.5, with Jenkins running. I've installed Robot framework plugin for jenkins, installed python 2.7 with Robot Framework (pybot works). I also wrote pretty easy program using NetBeans maven project with one unit test. My goal is to use RF in order to run said test.
At first i've tried to use Python version of RF, but eventually did it with jar stand-alone.
So my questions are:
1. Is it possible to add java libraries with keywords to Python version of RF or do i have to use jar stand-alone?
2. If i have to use .jar stand-alone, how can i run working test case on jenkins?
I've literally tried everything that i've found on this site (that's why eventually test-case worked), but i couldn't find anything else specificaly about what i'm asking.
You can use Jar edition with jenkins by using execute shell command
java -jar robotframework-3.0.jar -P TestedJarName.jar -d FolderForLogs RobotScript.txt
This will let you run test script. In script, you have to specify library with keywords - in other words, where in package is you .java file. For example, if you want to test Main.java that is in com.main package, you must write
Library com.main.main
Now, you can use all methods from Main.java
If you want just python script that runs maven tests, you just run it through shell pybot testname.txt
In text u need something like that Run mvn test and that's all.

Netbeans javac command

I am relatively new to Netbeans and Java, when I compile a project in Netbeans is there a way to view the equivalent javac commands, ie what I would have to run command line to produce the same result?
I use Netbeans 7.3.1 and you can see the building/compiling process in the output windows when you're building the program. Netbeans (my version) uses ANT to build program, so it produces a .jar.
If you want to know more about the details of how they compile a project, you can take a look at ANT http://ant.apache.org/, it's an useful build tool.
On your computer go to C:\Program Files\Java\jdk(the version you use)\jre\bin.
In bin you will find the commands you can use at the Command Prompt.
As David pointed, Netbeans uses Ant as its build tool, this means it uses a tool to parse a script that describes how to build each part of your project.
If you consider a simple Java program that is made of a single class this may not be significant and you could probably build it manually in the command line. However, any significant project (anything that does any interesting work) will need to compile many files, build the archive structure and every other task related to packing your application.
So, for a short answer you would have to consider the context:
1 - a simple class - yes you can compile manualy reading the output from the console
2 - for a simple project (that means, many classes) - yes, but starts to gets complicated
3 - for a real project (that means, many classes and resources) - no, it is not viable (and this means reasonable and confortable) to do it manualy.
For more info on compiling Java programs (which I think is your real interest) you should check the Javac page for a start (find it here).

Bash Script to execute Java Project

I usually compile and execute from Java project using eclipse IDE. Now, I need to write a bash script to submit this task to a cluster. My project contains 3 packages and has been written as per the Maven architecture. Can anyone hint me as to how can I include the task of executing the java program in the my bash script?
I tried different things like first trying to execute the project using command line but it does not work. I already read the replies provided in this post: Compiling and running multiple packages using the command line in Java and some others, but didn't help.
Thank you for your help.
I strongly suggest you look into something like the Maven App Assembler plugin. I don't know about your cluster but the mentioned plugin can create run scripts for most major OSes and is highly configurable.

Trouble installing Boilerpipe

This is the third time I've installed it. I had it working on Windows, and up until a few days ago on Linux. I've done all I can do and I don't understand how to run this Java program.
The source code is a folder with a lib, src some jars and a classpath and project file.
The classpath file makes some declarations like classpathentry=src/main and path=lib, path=src.
All of these make sense. There is a folder 'main' inside 'src'.
The tiny file I'm trying to run starts off by
import de.l3s.boilerpipe.demo
I'm trying to run 'Oneliner.java'. I cannot compile it.
No matter what/where that class file is, I cannot run it. It results in a noclassdeffound.
I've run it in the main, the src, the root, the demo, the ... anywhere.
I've tried compiling it in different directories, running it with various java command line switches that were recommended. Supposedly you can have it 'search' for the file, which I've yet to experience. The sheer stubbornness of this java environment is terrifying. And massively humiliating for me.
I had the same problem with installing it. The 'Getting Started' page is poor quality.
My solution was to use a python wrapper, which you can find here: https://github.com/misja/python-boilerpipe
It takes care of all of the dependencies you'll need (however, you might be missing jpype if you're on a Mac. In that case, you'll need to install it manually from: http://jpype.sourceforge.net/).
The best way to start using the boilerpipe algorithm (and to see what it is for) is to use the demo site:
http://boilerpipe-web.appspot.com/
If you want to integrate the boilerpipe library into your applications, or even intent to modify/improve the code, you will definitely need solid Java programming skills.
As a quick-start I suggest that you install a recent version of the Eclipse IDE for Java Developers and import boilerpipe-core as a project. This avoids pretty much of the classpath configuration, and almost everything should be set up correctly for you.
The classpath file you mentioned is probably ".classpath", which is part of the Eclipse project configuration. You don't need it unless you want an Eclipse project.

Categories