Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making executable file in Selenium WebDriver with Java

Is it possible to make Selenium WebDriver executable file in java? I have written code in java for data driven testing using Selenium WebDriver. I want to make it executable file so that outside eclipse one can execute it.

package pkg;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class LogingS {
  private WebDriver driver;
  private String baseUrl;

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://www.example.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testLogingS() throws Exception {
    driver.get(baseUrl);
    System.out.println("The current Url: " + driver.getCurrentUrl());
    driver.findElement(By.id("id_email")).clear();
    driver.findElement(By.id("id_email")).sendKeys("com");
    Thread.sleep(1000);
    driver.findElement(By.id("id_password")).clear();
    driver.findElement(By.id("id_password")).sendKeys("123");
    Thread.sleep(1000);
    System.out.println("The current Url: " + driver.getCurrentUrl());
    driver.findElement(By.id("btn_login")).submit();
    Thread.sleep(5000);
    System.out.println("The current Url: " + driver.getCurrentUrl());

  }

  @After
  public void tearDown() throws Exception {

  }
}
like image 751
ShutterSoul Avatar asked May 04 '26 17:05

ShutterSoul


1 Answers

To create a new JAR file in the workbench:

  1. Either from the context menu or from the menu bar's File menu, select Export.

  2. Expand the Java node and select JAR file. Click Next.

  3. In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field.

  4. In the Select the export destination field, either type or click Browse to select a location for the JAR file and Finish

  5. Open CMD, move upto your .jar

  6. Call jar file using following command :- java -jar xxx.jar

like image 199
Reshmi Aneesh Avatar answered May 06 '26 06:05

Reshmi Aneesh