Selenium java-maven ☕

POM DEL PROYECTO SOLO PARA DEBUGUEAR (MAS ABAJO SE ENCUENTRA LOS PLUGINS A AGREGAR PARA CREAR UN .JAR EJECUTABLE)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mavenproject1</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
</dependencies>
</project>

JAVA

package com.mycompany.testing;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedCondition;
import java.lang.*;
import java.util.*;
import org.openqa.selenium.support.ui.Select;
import java.net.URL;
import java.net.MalformedURLException;

/**
*
* @author eugenio
*/
public class NewMain {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "/home/eugenio/Descargas/chromedriver");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.envioscaracol.com/");
driver.findElement(By.cssSelector("button.close.negro")).click();
pausa(500);
driver.findElement(By.linkText("Entrar")).click();
pausa(500);
driver.findElement(By.id("login_string")).click();
pausa(500);

}
public static void pausa(long sleeptime) {
try {
Thread.sleep(sleeptime);
} catch (InterruptedException ex) {
}
}

}

POM LISTO PARA SER COMPILADO Y CREAR UN .JAR

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>testing</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
</dependencies>

<!-- CODIGO A AGREGAR PARA PODER CREAR UN .JAR -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mycompany.testing.NewMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<!-- FIN -->


</project>

URL de descarga ChromeDriver: http://chromedriver.storage.googleapis.com/index.html?path=2.23/

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *