Setting Up and Running Selenium Scripts in Terminal on Mac Machines with Maven

Modified on Tue, 21 May 2024 at 10:46 AM

Prerequisites



Before executing the scripts on a Mac operating system to open your preferred application, ensure that you have performed the following. If Java and Maven are already installed on the system, you can skip the prerequisite steps related to their installation and configuration. Proceed with the steps for running the scripts.

  1. Install the latest version of Java or a compatible version.  If Java is not installed, download the Java installer from Oracle Website, follow the on-screen instructions to install it.

  2. Set up the Java Path by opening the .bash_profile in your preferred text editor and add the following line:
    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin/Java
    In this example, nano is the text editor.
    To run the nano ~/.bash_profile command on a Mac:
    1. Open Terminal:

      You can find Terminal in the "Utilities" folder within the "Applications" folder, or you can use Spotlight search (Cmd + Space, then type "Terminal").

    2. Run the Command:
      In the Terminal window, type nano ~/.bash_profile and press Enter. This command opens the Bash profile file (~/.bash_profile) in the Nano text editor or your preferred text editor. If the file doesn't exist, Nano creates a new one. The '~' represents your home directory.


    3. Ensure to paste the path and enter the following commands to save and exit.

      1. Press Ctrl + O to write the changes, then press Enter.

      2. Press Ctrl + X to exit Nano.
        These commands in the nano text editor are used to save the changes and exit the editor.


  3. Ensure that a compatible Maven version or the latest version is installed. If Maven is not installed, download it from Maven website.
    After downloading, extract it using the following command:
    $ tar -xvf apache-maven-3.9.6-bin.tar.gz
    The binaries will be extracted in the “apache-maven-3.9.6” directory. You can save it to the appropriate folder.

  4. Set up the Maven environment variables M2_HOME and PATH by adding the following lines to the end of the .bash_profile file.

    Add the Maven bin directory to the Path variable. Open .bash_profile in your preferred text editor (Refer to the step 2 to run the nano ~/.bash_profile command) and add the following lines:
    export M2_HOME=/Library/apache-maven-3.9.6
    export PATH="${M2_HOME}/bin:${PATH}"

    Make sure to save and exit the editor.

  5. After setting the path for both Java and Maven, apply the changes in the .bash_profile file by running the following command:
    source ~/.bash_profile
    
    
  6. After reloading the shell configuration, exit the current terminal and reopen a new terminal. Check the Java or Maven versions to verify the installations by running the appropriate commands:
    To verify Java version, run the following command: 
     Java - version
    To verify Maven version, run the following command: 
    mvn -v


Running Selenium Scripts in Terminal on Mac operating system 

To run scripts on Mac computer, use the Terminal and perform the following:


  1. Navigate to the folder where the Script are downloaded, and open the Terminal from this location as shown:

  2. Run the following command to trigger the script to launch the preferred application.

    mvn test
    
    

  3. You will be able to view the preferred application in the chosen browser.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article