0

I created a .bat file in Windows and launching it from the Windows console and it worked perfectly. Now I got a requirement to execute it from Linux so the .bat file doesn't work, after searching I found you need to create a .sh file .

This is what I used:

export projectLocation=../Demo_Automatisation
cd $projectLocation
export classpath=$projectLocation/bin;$projectLocation/lib/*
java org.testng.TestNG $projectLocation/testng.xml

but I am getting an error:

ExecutionAuto.sh: line 3: ../Demo_Automatisation/lib/SparseBitSet-1.2.jar: Permission denied
+ java org.testng.TestNG ../Demo_Automatisation/testng.xml
Error: Could not find or load main class org.testng.TestNG
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG

I don't have the smallest clue about why is this happening, can someone assist me with this?

7
  • Linux is case sensitive, so I think it should be CLASSPATH, not classpath: export CLASSPATH=$projectLocation/bin;$projectLocation/lib/*
    – pavelsaman
    Dec 9, 2021 at 10:59
  • it did nothing i tried everything possible and i dont understand i am even executing it as sudo and i still get that permission denied
    – Yan
    Dec 9, 2021 at 11:05
  • Hard to say, perhaps something wrong with your installation of java (what does java -version tell you?). Try to reinstall it. Install it with your package distro manager. "Permission denied" can also mean you don't have the execute bit set.
    – pavelsaman
    Dec 9, 2021 at 11:08
  • do the jar file not work in linux ?
    – Yan
    Dec 9, 2021 at 11:27
  • You can bundle your Java code into a jar file and execute it in Linux. This will not be a problem.
    – pavelsaman
    Dec 9, 2021 at 11:31

2 Answers 2

0

To run your Selenium project via a terminal in Linux,

  1. You can export your project into a JAR file and then execute that JAR file from the Terminal in Linux.

If you are using Eclipse, you can export your project as a runable JAR and package/extract your libraries into the JAR file.

enter image description here

Also, ensure required external libraries are in a proper/same folder as you might have set it up in your code.

enter image description here

Once done this, you can open terminal and then run this command,

java -jar /<path to your jar file>/name-of-file.jar

This should run your Selenium project via the terminal.


  1. PS: Haven't tried this first hand.

If you are using Maven or TestNG you can also try this,

Make sure to compile your project code. In case of Eclipse, your compiled code can be found in your eclipse-workspace/<your project folder>/bin folder.

Also ensure that all your dependencies (Selenium or other) are in a single/central folder accessible by the project. All your JAR files should be within this folder.

So now, your project's directory structure will look something like this,

/bin - Has all test packages. Compiled code.
/src - Has all your source files. Un-compiled code.
/lib - All the required libraries.

Now, open the terminal and run these steps,

  1. set classpath=/<path to your project folder>/bin;/<path to your project folder>/lib/*

  2. java org.testng.TestNG testng.xml

This should run your tests via the Terminal.

To execute particular test from the testng.xml file you can try

org.testng.TestNG -testnames “test-name-here” testng.xml
0
java -cp "$projectLocation/bin:$projectLocation/lib/*"  org.testng.TestNG $projectLocation/testng.xml

Using colon instead of semicolon should fix this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.