Archiv der Kategorie: Java

Trainingseinheit: Arrays in java – Lohnt sich das goldschürfen?

Du bist Chefgeologe bei einem kleinen ehrgeizigen deutschen Unternehmen, welches im Amazonas-Gebiet nach Gold sucht. Während Deine Kollegen jedoch in tropischer Hitze vor Ort buddeln müssen, sitzt Du entspannt im wohlklimatisierten Büro in Deutschland und berechnest für Sie in Java, in welchem Abbaugebiet es sich lohnt, das Schürfen nach Aurum zu beginnen.

In jedem potenziellen Schürfgebiet (entspricht einem Wert im Array) – haben Deine Kollegen unterschiedliche Mengen an Gestein für die Exploration getestet. Im ersten Array sind die Tonnen Gestein gespeichert. Im zweiten Array sind die entsprechenden Mengen an Gold in Gramm gespeichert:

double[] abgetragenesGesteinInTonnen = {2.6, 3.1, 4.5, 2.5, 3.4, 1.5, 2.2, 2.7, 0.9, 1.0};
double[] geschuerftesGoldInGramm = {1.2, 0.4, 5.0, 1.0, 0.9, 0.8, 1.2, 1.5, 0.3, 0.6};

Das Schürfen lohnt sich erst ab 0,5 Gramm Gold pro Tonne Gestein
In welchem Gebiet lohnt es sich also eine Schürfgenehmigung bei der regionalen Behörde für Bodenschätze zu beantragen?

Quick Start of running Selenium WebDriver against PhantomJS in Java on Windows (Plain Java)

This is the quickstart without Maven, without IDE – just plain Java. For the quickstart with Maven look here
The browser with the probably highest speed and lowest memory consumption in Selenium world: the headless PhantomJS
[25.Feb.2014]: Ghostdriver is not ripe yet due to lack of enough stable maintainers: https://github.com/detro/ghostdriver/issues/140
[Note]: The development of Selenium and GhostDriver (which is the bridge between PhantomJS and Selenium) isn’t synchronized yet. So maybe the most actual versions of Selenium Server and GhostDriver may not work together. An (older) combination that fits:
* PhantomJS 1.9.2
* GhostDriver 1.0.4
* Selenium 2.34
1.) If you haven’t done yet, download the Java JDK from the download page (take the most actual Java Platform (JDK)). Execute it and follow the wizard. After that, set PATH.
2.) Download Selenium-Server-Standalone(!) 2.34.0 from
http://code.google.com/p/selenium/downloads/list?can=1&q=
On my notebook I have put it in C:\Users\IT Kosmopolit
3.) Download phantomjs-1.9.2-windows.zip here and extract it to C:\Program Files (x86)
4.) Add C:\Program Files (x86)\phantomjs-1.9.2-windows to the PATH-variable
5.) Download phantomjsdriver 1.0.4 from
http://mvnrepository.com/artifact/com.github.detro.ghostdriver/phantomjsdriver/1.0.4
On my notebook I have put it in C:\Users\IT Kosmopolit
6.) Save the following codesnippet as Example.java. On my notebook I have put it in C:\Users\IT Kosmopolit
Sample Code

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
public class Example {
public static void main(String[] args) {
WebDriver driver = new PhantomJSDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}

7.) Open the Command Prompt and compile with javac:

javac -classpath "C:\Users\IT Kosmopolit\selenium-server-standalone-2.34.0.jar;C:\Users\IT Kosmopolit\phantomjsdriver-1.0.4.jar" Example.java

8.) Execute in the Command Prompt

java -classpath .;"C:\Users\IT Kosmopolit\selenium-server-standalone-2.34.0.jar;C:\Users\IT Kosmopolit\phantomjsdriver-1.0.4.jar" Example

9.) If you get a result like this, you’re done
success

Quick Start of running Selenium WebDriver against PhantomJS in Java on Windows (with Maven)

This is the quickstart with Maven. For a quickstart without Maven, look here
The browser with the probably highest speed and lowest memory consumption in Selenium world: the headless PhantomJS
[Update 26.11.2013]: Ghostdriver is not ripe yet due to lack of enough stable maintainers: https://github.com/detro/ghostdriver/issues/140
[Note]: The development of Selenium and GhostDriver (which is the bridge between PhantomJS and Selenium) isn’t synchronized yet. So maybe the most actual versions of Selenium Server and GhostDriver may not work together. A combination that fits:
* PhantomJS 1.9.2
* GhostDriver 1.0.4
* Selenium 2.34
Setup is really quick
1.) Download phantomjs-1.9.2-windows.zip here and extract it to C:\Program Files (x86)
2.) Add C:\Program Files (x86)\phantomjs-1.9.2-windows to the PATH-variable
3.) Add in pom.xml

        <dependency>
            <groupId>com.github.detro.ghostdriver</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.0.4</version>
        </dependency>

4.) Maybe change the version of selenium in pom.xml

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>2.34.0</version>
        </dependency>

Sample Code

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
public class Example {
    public static void main(String[] args) {
        WebDriver driver = new PhantomJSDriver();
        driver.get("http://www.google.com");
        WebElement element = driver.findElement(By.name("q"));
        element.sendKeys("Cheese!");
        element.submit();
        System.out.println("Page title is: " + driver.getTitle());
        driver.quit();
    }
}

Looks so good
… if you’ve done right – your result should look like that:
GhostDriver_Selenium_PhantomJS
Speedy Testing!