Automation – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Sat, 17 Dec 2022 10:54:03 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 Setup Selenium with Python and Chrome Driver on Ubuntu & Debian https://tecadmin.net/setup-selenium-with-python-on-ubuntu-debian/ https://tecadmin.net/setup-selenium-with-python-on-ubuntu-debian/#comments Sun, 19 Jun 2022 04:12:49 +0000 https://tecadmin.net/?p=30109 Selenium is a versatile tool that can be used for automating browser-based tests. It has a wide range of features that make it an ideal choice for automating tests. Selenium can be used to automate tests for web applications and web services. Selenium supports a number of programming languages, including Java, C#, Python, and Ruby. [...]

The post Setup Selenium with Python and Chrome Driver on Ubuntu & Debian appeared first on TecAdmin.

]]>
Selenium is a versatile tool that can be used for automating browser-based tests. It has a wide range of features that make it an ideal choice for automating tests. Selenium can be used to automate tests for web applications and web services. Selenium supports a number of programming languages, including Java, C#, Python, and Ruby.

This makes it possible to write tests in the language that you are most comfortable with. In addition, Selenium has a large user community that provides support and help when needed.

In this blog post, you will learn to set up a Selenium environment on an Ubuntu system. Also provides you with a few examples of Selenium scripts written in Python.

Prerequisites

You must have Sudo privileged account access to the Ubuntu system.

One of the examples also required a desktop environment to be installed.

Step 1: Installing Google Chrome

Use the below steps to install the latest Google Chrome browser on Ubuntu and Debian systems.

  1. First of all, download the latest Gooogle Chrome Debian package on your system.
    wget -nc https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 
    
  2. Now, execute the following commands to install Google Chrome from the locally downloaded file.
    sudo apt update 
    sudo apt install -f ./google-chrome-stable_current_amd64.deb 
    

    Press ‘y’ for all the confirmations asked by the installer.

This will complete the Google Chrome on your Ubuntu or Debian system. This will also create an Apt PPA file for further upgrades.

Step 2: Installing Selenium and Webdriver for Python

We will use a virtual environment for running Python scripts. Follow the below steps to create Python virtual environment and install the required python modules.

  1. Create a directory to store Python scripts. Then switch to the newly-created directory.
    mkdir tests && cd tests 
    
  2. Set up the Python virtual environment and activate it.
    python3 -m venv venv 
    source venv/bin/activate 
    

    Once the environment is activated, You will find the updated prompt as shown below screenshot:

    Create Python Environment for Selenium on Ubuntu
    Create Python Environment for Selenium on Ubuntu
  3. Now use PIP to install the selenium and webdriver-manager Python modules under the virtual environment.
    pip install selenium webdriver-manager 
    

    Installing Selenium and Webdriver Python Module on Ubuntu & Debian
    Installing Selenium and Webdriver Python Module on Ubuntu & Debian

Example 1: Selenium Python Script with Headless Chrome

Your system is ready to run Selenium scripts written in Python. Now, create a sample selenium script in Python that fetches the title of a website.

This script will run headless, So you can run it without an X desktop environment. You can simply SSH to your system and run the below example:

  1. Create a Python script and edit it in your favorite text editor:
    nano test.py 
    
  2. Copy-paste the following Selenium Python script to the file.
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    
    options = Options()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
    
    driver.get("https://python.org")
    print(driver.title)
    driver.close()

    Press CTRL + O to save content to the file and press CTRL + X to close the editor.

  3. Now, run this Python script in a shell.
    python test.py 
    

    You will see the output something like the below:

    Running Selenium Python Script in Ubuntu & Debian
    Running the Selenium Python Script

Example 2: Selenium Python Script with Chrome GUI

In order to run this example, the Ubuntu system must have installed a Desktop environment. If the desktop is not installed, use another tutorial to install the Desktop environment on Ubuntu systems.

Now, log in to the desktop interface and try to run the below example.

  1. Open a command prompt, then create a new Python script and edit it in your favorite text editor.
    nano test.py 
    
  2. Copy-paste the below snippet in the file:

    import time
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from webdriver_manager.chrome import ChromeDriverManager
    
    options = Options()
    # options.add_argument('--headless')
    # options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
    
    driver.get('http://www.google.com')
    search = driver.find_element(by=By.NAME, value="q")
    search.send_keys("Hey, Tecadmin")
    search.send_keys(Keys.RETURN)
    
    time.sleep(5)
    driver.close()

    Write the changes to file with CTRL + O and close this with keyboard shortcut CTRL + X

  3. This is a Selenium script written in Python, that will launch the Google Chrome web browser and search for a defined string. then close the browser.
  4. Run the Python script in the terminal:
    python test2.py 
    

    You will see that a Browser window will open and perform the defined tasks in the script. See the below screencast of the run:

Conclusion

In this tutorial, you have learned about the configuration of Selenium for Python on Ubuntu and Debian Linux systems. Also provides you with two Selenium examples. Hope this tutorial helps you to understand to run Selenium with Python.

The post Setup Selenium with Python and Chrome Driver on Ubuntu & Debian appeared first on TecAdmin.

]]>
https://tecadmin.net/setup-selenium-with-python-on-ubuntu-debian/feed/ 1 Automation Archives – TecAdmin nonadult
Setup Selenium with Python and Chrome on Fedora https://tecadmin.net/configuring-the-selenium-with-python-on-fedora/ https://tecadmin.net/configuring-the-selenium-with-python-on-fedora/#respond Sat, 18 Jun 2022 04:40:38 +0000 https://tecadmin.net/?p=30102 Selenium is a versatile tool, which is widely used for automating browser-based tests. It can be used to automate tests for web applications and web services. Selenium supports a number of programming languages, including Java, C#, Python, and Ruby. This makes it possible to write tests in the language that you are most comfortable with. [...]

The post Setup Selenium with Python and Chrome on Fedora appeared first on TecAdmin.

]]>
Selenium is a versatile tool, which is widely used for automating browser-based tests. It can be used to automate tests for web applications and web services. Selenium supports a number of programming languages, including Java, C#, Python, and Ruby.

This makes it possible to write tests in the language that you are most comfortable with. In addition, Selenium has a large user community that provides support and help when needed.

This tutorial will help you to configure the environment for Selenium with Python and Chrome on Fedora. We will discuss an example written in Python.

Prerequisites

Assuming you have access to a Fedora system with a Sudo privileged account.

This tutorial can be run with GUI access or shell access only.

Step 1 – Installing Google Chrome

You can use firefox or Google Chrome web browser to run your selenium test cases. In this article, we will discuss examples with the Google Chrome web browser.

So, Let’s install Google chrome first. Enable the google-chome repository with the below-mentioned commands:

sudo dnf install fedora-workstation-repositories 
sudo dnf config-manager --set-enabled google-chrome 

Now, install the latest google chrome stable web browser:

sudo dnf install google-chrome-stable 

Google Chrome will be installed on your Fedora system.

Step 2 – Setup Python Environment

We will create a virtual environment for running our Python test cases. Follow the below steps to create Python virtual environment, and install the required modules.

  1. Installing Python and its virutal environent module.
    sudo dnf install python3 python3-virtualenv 
    
  2. Create a directory for contianing python environment and scripts..
    mkdir tests && cd tests 
    
  3. Create virutal environment
    python3 -m venv venv 
    source venv/bin/activate 
    
    Creating Python Virtual Environment for Selenium on Fedora
    Creating Python Virtual Environment for Selenium on Fedora
  4. Installing selenium and webdriver manager using PIP under the virtual environemnt.
    pip install selenium webdriver-manager 
    

    Installing selenium for Python on Fedora
    Installing selenium for Python on Fedora

Step 3 – Running an Example with Selenium Python

The Python virtual environment is ready to run Selenium scripts. Let’s run an example script, that opens a website in a headless (Useful for remote ssh access) google chrome browser and prints the title of the website.

Make sure the Python virtual environment is active. you can identify that using the terminal prompt. Now create a Python script and edit it in a text editor.

nano test1.py 

Copy-paste the below snippet to file:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

driver.get("https://python.org")
print(driver.title)
driver.close()

Press CTRL +O to write changes and then press CTRL + X to exit from the editor.

Now, run your Python script:

python test1.py 

You will see the output something like below:

Running Selenium Python Script on Fedora
Running Selenium Python Script on Fedora

At the first run, the script will download the latest chromedriver and place it in your system to use for the next executions.

In the output, you can see the title of the given website is printed on the screen.

Conclusion

Selenium is a popular tool among website testers for running automatic test cases. In this tutorial, we have discussed configuring the Selenium environment with Python scripts.

The post Setup Selenium with Python and Chrome on Fedora appeared first on TecAdmin.

]]>
https://tecadmin.net/configuring-the-selenium-with-python-on-fedora/feed/ 0
Deploy Angular App to Firebase with Github Actions https://tecadmin.net/deploy-angular-app-to-firebase-with-github-actions/ https://tecadmin.net/deploy-angular-app-to-firebase-with-github-actions/#respond Fri, 19 Feb 2021 05:19:27 +0000 https://tecadmin.net/?p=24598 These set of instruction helps you to setup Github Actions to build an Angular project and deploy to the Firebase hosting on push event. Even you can refer this tutorial to build any node.js application and deploy to firebase. Github actions allows you to automate, customize, and execute your software development workflows right in your [...]

The post Deploy Angular App to Firebase with Github Actions appeared first on TecAdmin.

]]>
These set of instruction helps you to setup Github Actions to build an Angular project and deploy to the Firebase hosting on push event. Even you can refer this tutorial to build any node.js application and deploy to firebase.

Github actions allows you to automate, customize, and execute your software development workflows right in your repository. It is the best way to create and maintain a Continuous Integration/Continuous Deployment (CI/CD) lifecyle for your application.

We assume you already have pushed your application to Github repository. Let’s start with the configuration of Github actions.

Step 1 – Create Github Action

Login to your Github account and access your repository. In your repository click on Actions tab, then click “set up a workflow yourself” link.

See below screenshot for reference:

Create Github Actions Workflow

Step 2 – Create a Workflow

Once you click on setp workflow link, this will edit a new file “.github/workflows/main.yml” under the repository. Which contains some default configuration for the Workflow.

You will see the newly crated file, something like this:

jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      # Runs a single command using the runners shell
      - name: Run a one-line script
        run: echo Hello, world!

      # Runs a set of commands using the runners shell
      - name: Run a multi-line script
        run: |
          echo Add other actions to build,
          echo test, and deploy your project.

Step 3 – Customize Your Workflow

Now, we will customize the workflow configuration file based on our requirements. In this step we have breakdown the configuration step by step to make you understand. Even you can skip this step, as the full configuration file is provided in next steps.

  1. Define workflow name – This is an optional step, but you can give a name to your workflow.
    name: deploy_to_firebase_hosting
    
  2. Customize job name – All the jobs are defined under “jobs:” sections. First, we change the defualt job name build to firebase-deploy. You can change this to any name as per suitable to you.
    jobs:
      firebase-deploy:
    
  3. Customize trigger – The default workflow triggers on each push into any branches. You may need to limit this to specific branches.

    For example, enable workflow trigger only on push to main or release/* branches:

    on:
      push:
        branches:
        - main
        - release/*
    
  4. Update checkout action – The default workflow uses actions/checkout@v2, which is the latest version. So no need to make changes here but you can still change this to most current actions/checkout@master.
    - uses: actions/checkout@v2
    
  5. Customize node.js build trigger – Now, define the Node.js version and build commands for your Angular application. For example, we are using the Node.js 12.x version to build this application.
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@master
      with:
        node-version: '12.x'
    - run: npm install
    - run: npm run build:prod
    
  6. Deploy to Firebase – The last step is to deploy your application to the Firebase functions.
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@master
      with:
      node-version: '12.x'
    - run: npm install
    - run: npm run build:prod
    - uses: w9jds/firebase-action@master
      with:
        args: deploy --only hosting
      env:
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
    

    As per above configuration the deployment will be done to firebase hosting only. You can even change args value to “deploy --only function” to deploy firbase functions.

Now click on Start commit on the right side to commit your new workflow.

Step 4 – Setup Firebase Token

Github actions deploy job need a FIREBASE_TOKEN for the authentication to deploy code on firebase. You can generate a token using firebase cli tools on your system.

First, install firebase-tools using npm.

npm i -g firebase-tools 

Then run the firebase login:ci command on terminal:

firebase login:ci  

This will show you link on on your terminal, Open this link in web browser and complete authorization. This will show you a token to use for CI tasks.

Example: firebase deploy --token "\$FIREBASE_TOKEN"

As it is not safe to keep this token in configuration file. Add this token to Github secrets.

In your Github repository, Go to Settings > Secrets > New repository secret:

Use FIREBASE_TOKEN as name and enter the secret code in value section. Then click on Add secret button.

Step 5 – Final Workflow Configuration

Your final workflow configuration file should look something like this in the text editor:

file: .github/workflow/main.yml

name: deploy_to_firebase_hosting

on:
  push:
    branches:
    - master
    - release/*

jobs:
  firebase-deploy:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@master
      with:
        node-version: '12.x'
    - run: npm install
    - run: npm run build:prod
    - uses: w9jds/firebase-action@master
      with:
        args: deploy --only hosting
      env:
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

Now you can commit the workflow configuration file to your repository. This workflow is added to .github/workflows/main.yml. You can change main.yml fielname of your choice with .yml extension.

Next, Go ahead and push some changes to your Github repository. This will tirgger the Github action and perform the steps defined in workflow.

Github action deployed to firebase functions successfully

Conclusion

In this tutorial, you have learned to build an Angular project using Github actions and deploy to firebase hosting.

You can also visit Github actions documentation for more details.

The post Deploy Angular App to Firebase with Github Actions appeared first on TecAdmin.

]]>
https://tecadmin.net/deploy-angular-app-to-firebase-with-github-actions/feed/ 0
How To Install and Configure Ansible on Debian 10 https://tecadmin.net/install-and-configure-ansible-on-debian-10/ https://tecadmin.net/install-and-configure-ansible-on-debian-10/#comments Sat, 03 Oct 2020 07:18:54 +0000 https://tecadmin.net/?p=23008 Ansible is a free and easy to use automation tool for managing multiple remote hosts from the single machine. It provides you with an easy to configure for a large number of remote hosts. For example, you are performing the same tasks over multiple machines, Ansible provides you the option to automate these tasks. Ansible [...]

The post How To Install and Configure Ansible on Debian 10 appeared first on TecAdmin.

]]>
Ansible is a free and easy to use automation tool for managing multiple remote hosts from the single machine. It provides you with an easy to configure for a large number of remote hosts. For example, you are performing the same tasks over multiple machines, Ansible provides you the option to automate these tasks.

Ansible is a better alternatives of the other popular infrastructure automation tools available like Chef and Puppet. You don’t need to install any client software on nodes to manage through Ansible server. It uses SSH connection to execute tasks on hosts.

This tutorial will help you to install and configure Ansible on Debian 10 Linux systems.

Prerequisites

For this tutorial, I have the following hosts:

  • One Control Node – To build your infra with Ansible, you need a control node where Ansible server will run. This is known as Ansible control node.
  • One or more Hosts – We have three hosts running with different-2 operating systems.
    • Two hosts with Ubuntu 20.04 LTS
    • One host with CentOS 8

Step 1 – Configure SSH Keys

Ansible control node uses ssh connection to connect hosts. You can configure Ansible to connect hosts using the password or key-based ssh access. In this tutorial, we will use both (password and key based ssh) types to connect hosts from control node.

Login to Ansible control node and generate ssh key pair (if not generated):

ssh-keygen -t rsa 

Just press “Enter” to all the input asked by the command.

Then copy the public key to the remote hosts, you need to connect via key-based:

ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.1.101 
ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.1.102 

Step 2 – Installing Ansible on Debian

The Ansible debian packages are available under the official Apt repository. You just need to add the PPA to your system. Use the following command to add Ansible debian repository to your system:

sudo apt-add-repository ppa:ansible/ansible 

Software Updater utility will update the packages cache on your system. So you have to run the following command to install or update Ansible on your Debian system

sudo apt update 
sudo apt install ansible 

Press ‘Y’ for all the installation confirmation to complete install process. Next, you need to configure Ansible server

Step 3 – Create Inventory File

You have installed Ansible server on your control node.

Now, you need to add the hosts to the Ansible server. Ansible allows to manage hosts in the form on hosts and groups. The Groups are used for performing one task on all remote hosts defined under it.

A single host can be added to multiple groups. Edit Ansible hosts configuration file. For example:

sudo nano /etc/ansible/hosts 

Add your hosts and organize them with groups:

[webservers]
web-host1
web-host2

[dbservers]
db-host1

[ubuntu]
web-host1
db-host1

[centos]
web-host2

The below image will help you to understand group and hosts under a group.

Per Host Configuration

You can create configuration files for individual hosts. All the hosts configuration file resides under /etc/ansible/host_vars directory with the same as hostname.

sudo mkdir /etc/ansible/host_vars/ 
sudo vi /etc/ansible/host_vars/web-host1 
  • 1’st Host – /etc/ansible/host_vars/web-host1
    ansible_ssh_host: 10.0.1.101
    ansible_ssh_port: 22
    ansible_ssh_user: root
    
  • 2’nd Host – /etc/ansible/host_vars/web-host2
    ansible_ssh_host: 10.0.1.102
    ansible_ssh_port: 22
    ansible_ssh_user: root
    
  • 3’rd Host – /etc/ansible/host_vars/db-host1
    ansible_ssh_host: 10.0.1.103
    ansible_ssh_port: 22
    ansible_ssh_user: root
    
  • In case you don’t have used Step 1 for the ssh connection for this host. You can also add one of the below methods to web-hosts1 configuration file for the authentication.

    ansible_ssh_pass: secret_password
    ansible_ssh_private_key_file: /home/rahul/.ssh/aws.pem
    

    Group Vars Configuration

    You can configure common variable settings of a Group under group configurations. The group file name must be same as the group name (eg: webservers) under group_vars directory.

    sudo mkdir /etc/ansible/group_vars 
    sudo vi /etc/ansible/group_vars/webservers 
    

    Add the common variables to this file used by all the hosts added under this group.

    ansible_ssh_port: 22
    ansible_ssh_user: root
    

    Step 4 – Testing Ansible Connection

    Your Ansible is ready to use. To test all nodes connectivity use ping module. Login to your Ansible server and execute following command:

    ansible -m ping all 
    

    You can also test connectivity for the specific host or groups.

    ansible -m ping web-host1         ## Specific host 
    ansible -m ping webservers        ## Specific group 
    

    You can also run any Linux command using the Ansible shell module. For example, execute the below command to test the free memory on web-host1.

    ansible -m shell -a 'free -m' web-host1 
    

    Install Ansible on Debian

    You can also perform the same task for a group. Just use group name instead of hostname.

    Conclusion

    In this tutorial, you have learned to install and configure Ansible on Debian 10 Linux system.

    The post How To Install and Configure Ansible on Debian 10 appeared first on TecAdmin.

    ]]> https://tecadmin.net/install-and-configure-ansible-on-debian-10/feed/ 2 How To Install and Configure Ansible on Ubuntu 20.04 https://tecadmin.net/install-and-configure-ansible-on-ubuntu-20-04/ https://tecadmin.net/install-and-configure-ansible-on-ubuntu-20-04/#respond Thu, 01 Oct 2020 06:55:12 +0000 https://tecadmin.net/?p=22979 Ansible is an automation tool for managing multiple remote hosts from the single machine. It provides you with an easy to configure for a large number of remote hosts. For example, you are performing the same tasks over multiple machines, Ansible provides you the option to automate these tasks. Ansible is a better alternatives of [...]

    The post How To Install and Configure Ansible on Ubuntu 20.04 appeared first on TecAdmin.

    ]]>
    Ansible is an automation tool for managing multiple remote hosts from the single machine. It provides you with an easy to configure for a large number of remote hosts. For example, you are performing the same tasks over multiple machines, Ansible provides you the option to automate these tasks.

    Ansible is a better alternatives of the other popular infrastructure automation tools available like Chef and Puppet. You don’t need to install any client software on nodes to manage through Ansible server. It uses SSH connection to execute tasks on nodes.

    This tutorial will help you to install and configure Ansible on Ubuntu 20.04 LTS Linux systems.

    Prerequisites

    We have one control node to configure Ansible server and three node servers to be managed. Here control node is running with Ubuntu 20.04 Linux system. First and third node is running with Ubuntu 18.04 server and Second node is running with centos 7 server.

    Here is list of nodes with IP address and hostnames:

    • Control node – 10.0.1.10 (control-node)
    • First node – 10.0.1.101 (web-host1)
    • Second node – 10.0.1.102 (web-host2)
    • Third node – 10.0.1.103 (db-host1)
    • Step 1 – Setup SSH Keys

      You can configure key based ssh for the remote Linux Ansible hosts. So password will not be required for SSH. Ansible also allows you to use a password for ssh, but key-based ssh is more secure.

      Login to the control node (10.0.1.10) and generate ssh key pair:

      ssh-keygen -t rsa 
      

      Just press “Enter” to all the input asked by the command.

      Copy the public key to all your remote nodes you need to connect via with SSH protocols.

      ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.1.101 
      ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.1.102 
      ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.1.103 
      

      Step 2 – Installing Ansible on Ubuntu

      You can install Ansible server from official packages repositories on Ubuntu system. Which has the latest debian packages. Execute the following command to setup Ansible PPA on your Ubuntu system.

      sudo apt-add-repository ppa:ansible/ansible 
      

      Software Updater utility will update the packages cache on your system. So you have to run the following command to install or update Ansible on your Ubuntu system

      sudo apt update 
      sudo apt install ansible 
      

      Enter ‘Y’ for all the installation confirmation to complete install process. Next, you need to configure Ansible server

      Step 3 – Configure Inventory File

      Your server is ready with Ansible for remote host management and automation. You can have a number of hosts you need and manage them with single Ansible server.

      Here you need to define your remote systems in Ansible hosts file (/etc/ansible/hosts). You can also make groups of hosts with similar types. Here you need to properly organize your hosts into groups. Groups are used for performing one task on all remote hosts defined under it.

      Edit Ansible hosts configuration file. For exmaple:

      sudo nano /etc/ansible/hosts 
      

      Add your hosts and organize them with groups. A host can be added under multiple groups.

      [webservers]
      web-host1
      web-host2
      
      [dbservers]
      db-host1
      

      The below image will help you to understand group and hosts under a group.

      Ansible Group and Hosts

      Single Host Vars Configuration

      You need to define settings for your hosts. The host-specific file must be with the same name as host (eg: web-host1) under the host_vars directory.

      sudo mkdir /etc/ansible/host_vars/ 
      sudo vi /etc/ansible/host_vars/web-host1 
      

      Add the SSH settings to this file for the web-host1.

      ansible_ssh_host: 10.0.1.101
      ansible_ssh_port: 22
      ansible_ssh_user: root
      

      Ansible Host Settings

      In case you don’t have used Step 1 for the ssh connection for this host. You can also add one of the below methods to web-hosts1 configuration file for the authentication.

      ansible_ssh_pass: secret_password
      ansible_ssh_private_key_file: /home/rahul/.ssh/aws.pem
      

      Group Vars Configuration

      You can configure common variable settings of a Group under group configurations. The group file name must be same as the group name (eg: webservers) under group_vars directory.

      sudo mkdir /etc/ansible/group_vars 
      sudo vi /etc/ansible/group_vars/webservers 
      

      Add the common variables to this file used by all the hosts added under this group.

      ansible_ssh_port: 22
      ansible_ssh_user: root
      

      Step 4 – Testing Ansible Connection

      Your Ansible is ready to use. To test all nodes connectivity use ping module. Login to your Ansible server and execute following command:

      ansible -m ping all 
      

      You can also test connectivity for the specific host or groups.

      ansible -m ping web-host1        ## Specific host 
      ansible -m ping webservers        ## Specific group 
      

      You can also run any Linux command using the Ansible shell module. For example, execute the below command to test the free memory on web-host1.

      ansible -m shell -a 'free -m' web-host1 
      

      Install Ansible on Ubuntu

      You can also perform the same task for a group. Just use group name instead of hostname.

      Conclusion

      In this tutorial, you have learned to install Ansible server on Ubuntu 20.04 system. Also configured remote hosts to be managed with Ansible server.

      The post How To Install and Configure Ansible on Ubuntu 20.04 appeared first on TecAdmin.

      ]]> https://tecadmin.net/install-and-configure-ansible-on-ubuntu-20-04/feed/ 0 Magento 2 Codebase & Database Backup Script https://tecadmin.net/magento2-backup-script/ https://tecadmin.net/magento2-backup-script/#respond Tue, 10 Mar 2020 16:56:33 +0000 https://tecadmin.net/?p=20672 This tutorial will help you to automate the Magento2 codebase and database backup process using a shell script. The script will perform automatic backups on a scheduled interval. The script also has the ability to remove older backups as per configuration. Setup Magerun2 You need to download and configure the Magerun2 script on your system. [...]

      The post Magento 2 Codebase & Database Backup Script appeared first on TecAdmin.

      ]]>
      This tutorial will help you to automate the Magento2 codebase and database backup process using a shell script. The script will perform automatic backups on a scheduled interval. The script also has the ability to remove older backups as per configuration.

      Setup Magerun2

      You need to download and configure the Magerun2 script on your system.

      wget https://files.magerun.net/n98-magerun2.phar
      mv n98-magerun2.phar /usr/local/bin/n98-magerun2
      chmod +x /usr/local/bin/n98-magerun2 
      

      Download Shell Script

      You can download Magento2 backup script from here. Alternativly, use below command to download script using wget command.

      wget https://tecadmin.net/wp-content/downloads/scripts/magento2-backup.sh
      

      You can also copy the script below and paste it in a file on your machine.

      #!/bin/bash
      
      #######################################################################################
      ##
      ##   Magento 2 database and codebase backup script
      ##   Written By: Rahul Kumar
      ##   Written on: Mar 06, 2020
      ##   Last Update: Mar 11, 2020
      ##
      #######################################################################################
      
      ################## Modify below values  ###############################################
      
      
      MAGENTO_DOCUMENT_ROOT="/var/www/magento2"
      BACKUP_PATH="/var/www/magento2/var/backups"
      
      BACKUP_RETAIN_DAYS=30     # Number of days to keep a local backup copy
      
      GZIP="/bin/gzip"
      RM="/bin/rm"
      MKDIR="/bin/mkdir"
      N98_MAGERUN2="/usr/local/bin/n98-magerun2"
      
      
      
      #######################################################################################
      ##################              Do not change below values              ###############
      
      export PATH=/bin:/usr/bin:/usr/local/bin
      TODAY="$(date "+%Y-%m-%d-%H-%M")"
      CURRENT_BACKUP_DIR="${BACKUP_PATH}/${TODAY}"
      
      #######################################################################################
      ##################              Functions               ###############################
      
      exit_on_error(){
              echo -e "$@"
              exit 99
      }
      
      maintenance_mode(){
              ${N98_MAGERUN2} sys:maintenance ${1} --skip-root-check --root-dir=${MAGENTO_DOCUMENT_ROOT}
      }
      
      check_cmds(){
          [ ! -x ${GZIP} ] && exit_on_error "FILENAME $GZIP does not exists. Make sure correct path is set in config section."
          [ ! -x ${RM} ] && exit_on_error "FILENAME $RM does not exists. Make sure correct path is set in config section."
          [ ! -x ${MKDIR} ] && exit_on_error "FILENAME $MKDIR does not exists. Make sure correct path is set config section."
          [ ! -x ${N98_MAGERUN2} ] && exit_on_error "FILENAME $N98_MAGERUN2 does not exists. \nDownload script from https://files.magerun.net/ and Make sure correct path is set in config section."
      }
      
      create_backup_dir(){
              [ ! -d ${CURRENT_BACKUP_DIR} ] && ${MKDIR} -p ${CURRENT_BACKUP_DIR}
      }
      
      database_backup(){
      
              ${N98_MAGERUN2} --skip-root-check --root-dir=${MAGENTO_DOCUMENT_ROOT} db:dump ${CURRENT_BACKUP_DIR}/database-${TODAY}.sql
      
              if [ $? -eq 0 ]; then
                      echo "Database backup successfully completed"
              else
                      maintenance_mode --off    ##### Disable mainenence even database backup failed
                      exit_on_error "Database backup failed. "
              fi
      }
      
      
      
      codebase_backup(){
      
              cd $MAGENTO_DOCUMENT_ROOT && \
              tar -cpzf ${CURRENT_BACKUP_DIR}/codebase-${TODAY}.tar.gz --exclude=var/* .
      
              if [ $? -eq 0 ]; then
                      echo "Codebase backup successfully completed"
              else
                      maintenance_mode --off    ##### Disable mainenence even codebase backup failed
                      exit_on_error "Codebase backup failed. "
              fi
      }
      
      
      cleanup_old_backup(){
      
              REMOVE_DIR_NAME=`date "+%Y-%m-%d-%H-%M" --date="${BACKUP_RETAIN_DAYS} days ago"`
      
              if [ ! -z ${BACKUP_PATH} ]; then
                        cd ${BACKUP_PATH}
                        if [ ! -z ${REMOVE_DIR_NAME} ] && [ -d ${REMOVE_DIR_NAME} ]; then
                                      rm -rf ${REMOVE_DIR_NAME}
                        fi
              fi
      }
      
      ########################################################################################
      ##################              Main (Calling functions)           #####################
      
      check_cmds
      create_backup_dir
      maintenance_mode --on
      database_backup
      codebase_backup
      maintenance_mode --off
      cleanup_old_backup
      
      
      ##########################################################################################
      ##################                      Script Ends Here                ##################
      ##########################################################################################
      

      Schedule Backup Scrpt

      Schedule this script using crontab on your system to run on a daily basis. Use below command to edit crontab configuration:

      crontab -e
      

      And add below entry at the end of file.

      0 0 * * * sh magento2-backup.sh
      

      Save file and close. You have successfully scheduled cronjob to run on 12:00 AM daily basis. To learn more about using the cronjob read this tutorial.

      The post Magento 2 Codebase & Database Backup Script appeared first on TecAdmin.

      ]]>
      https://tecadmin.net/magento2-backup-script/feed/ 0
      How to Setup Selenium with Chrome Driver on Fedora https://tecadmin.net/setup-selenium-with-chrome-driver-on-fedora/ https://tecadmin.net/setup-selenium-with-chrome-driver-on-fedora/#comments Mon, 17 Feb 2020 10:26:18 +0000 https://tecadmin.net/?p=20173 This tutorial will help you to set up Selenium with ChromeDriver on Fedora systems. This tutorial also includes an example of a Java program that uses the Selenium standalone server and ChromeDriver and runs a sample test case. This tutorial described how to set up a selenium server with a chrome driver on a Fedora [...]

      The post How to Setup Selenium with Chrome Driver on Fedora appeared first on TecAdmin.

      ]]>
      This tutorial will help you to set up Selenium with ChromeDriver on Fedora systems. This tutorial also includes an example of a Java program that uses the Selenium standalone server and ChromeDriver and runs a sample test case.

      This tutorial described how to set up a selenium server with a chrome driver on a Fedora system. Also, you will get a sample Java program to run a small test over selenium with a headless chrome driver.

      Prerequisites

      Login to your Fedora system with Sudo privileged account. Launch a terminal and execute the following commands to install the required packages on your system.

      sudo dnf install unzip wget java-11-openjdk java-11-openjdk-devel 
      

      Step 1 – Installing Google Chrome

      Enable the Google chrome repository for installing latest versions. Execute the following commands, this will enable google-chrome repo on your Fedora system:

      sudo dnf install fedora-workstation-repositories 
      sudo dnf config-manager --set-enabled google-chrome 
      

      Next install the Google chrome web browser:

      sudo dnf install google-chrome-stable  
      

      Step 2 – Install ChromeDriver

      You are also required to set up ChromeDriver on your system. ChromeDriver is a standalone server which implements WebDriver’s wire protocol for Chromium. The WebDriver is an open-source tool for automated testing of web apps across multiple browsers.

      wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip 
      unzip chromedriver_linux64.zip 
      

      You can find the latest ChromeDriver on its official download page. Now execute below commands to configure ChromeDriver on your system.

      sudo mv chromedriver /usr/bin/chromedriver 
      sudo chown root:root /usr/bin/chromedriver 
      sudo chmod +x /usr/bin/chromedriver 
      

      Step 3 – Download Required Jar Files

      The Selenium Server is required to run Remote Selenium WebDrivers. You need to download the Selenium standalone server jar file using the below commands or visit here to find the latest version of Jar file.

      wget https://selenium-release.storage.googleapis.com/3.13/selenium-server-standalone-3.13.0.jar 
      

      Also, download the TestNG jar file on your system.

      wget http://www.java2s.com/Code/JarDownload/testng/testng-6.8.7.jar.zip 
      unzip testng-6.8.7.jar.zip 
      

      Your Selenium server is now running with Chrome. Use this server to run your test cases written in Selenium using the Google Chrome web browser. The next step is an optional step and doesn’t depend on Step 5.

      Step 4 – Testing with Sample Java Application

      This is an optional step. It describes running a single test case using the Selenium standalone server and ChromeDriver. Let’s create a Java program using the Selenium server and Chrome Driver. This Java program will open a specified website URL and check if the defined string is present on the webpage or not.

      Create a Java program by editing a file in text editor.

      vim TecAdminSeleniumTest.java 
      

      Add the below content to the file.

      import java.io.IOException;
      
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.chrome.ChromeOptions;
      import org.openqa.selenium.chrome.ChromeDriver;
      import org.testng.annotations.Test;
      
      public class TecAdminSeleniumTest {
      
              public static void main(String[] args) throws IOException, InterruptedException {
                      System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
                      ChromeOptions chromeOptions = new ChromeOptions();
                      chromeOptions.addArguments("--headless");
                      chromeOptions.addArguments("--no-sandbox");
      
                      WebDriver driver = new ChromeDriver(chromeOptions);
      
                      driver.get("https://google.com");
      
                      Thread.sleep(1000);
      
                      if (driver.getPageSource().contains("I'm Feeling Lucky")) {
                              System.out.println("Pass");
                      } else {
                              System.out.println("Fail");
                      }
                      driver.quit();
              }
      }

      You can change the URL “https://google.com” with any other URL of your choice, Then also change the search string like “I’m Feeling Lucky” used in the above Java program. Save your java program and execute it. First, you need to set the Java CLASSPATH environment variable including the selenium-server-standalone.jar and testng-6.8.7.jar. Then compile the java program and run it.

      export CLASSPATH=".:selenium-server-standalone.jar:testng-6.8.7.jar" 
      javac TecAdminSeleniumTest.java 
      

      Then run command:

      java TecAdminSeleniumTest 
      
      Output
      Starting ChromeDriver 2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706) on port 10968 Only local connections are allowed. Feb 01, 2020 10:51:40 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS Pass

      You will see the results below. If the defined search string is found, You will get the message “Pass” and if the string is not found on the webpage, you will get the “Fail” message on the screen.

      Selenium test case results

      Conclusion

      You have successfully configured Selenium with ChromeDrive on your Fedora system. Now you can automate your test cases and run them periodically. I hope this tutorial contributes a little help to you with the automation testing. Please do not forget to share this tutorial.

      The post How to Setup Selenium with Chrome Driver on Fedora appeared first on TecAdmin.

      ]]>
      https://tecadmin.net/setup-selenium-with-chrome-driver-on-fedora/feed/ 3
      How to Setup Selenium with ChromeDriver on Ubuntu 22.04, 20.04 & 18.04 https://tecadmin.net/setup-selenium-chromedriver-on-ubuntu/ https://tecadmin.net/setup-selenium-chromedriver-on-ubuntu/#comments Mon, 19 Feb 2018 16:17:20 +0000 https://tecadmin.net/?p=15095 This tutorial will help you to set up Selenium with ChromeDriver on Ubuntu, and LinuxMint systems. This tutorial also includes an example of a Java program that uses a Selenium standalone server and ChromeDriver and runs a sample test case. Read This: Setup Selenium with Firefox on Ubuntu Step 1 – Prerequisites Execute the following [...]

      The post How to Setup Selenium with ChromeDriver on Ubuntu 22.04, 20.04 & 18.04 appeared first on TecAdmin.

      ]]>
      This tutorial will help you to set up Selenium with ChromeDriver on Ubuntu, and LinuxMint systems. This tutorial also includes an example of a Java program that uses a Selenium standalone server and ChromeDriver and runs a sample test case.

      Read This: Setup Selenium with Firefox on Ubuntu

      Step 1 – Prerequisites

      Execute the following commands to install the required packages on your system. Here Xvfb (X virtual framebuffer) is an in-memory display server for a UNIX-like operating system (e.g., Linux). It implements the X11 display server protocol without any display. This is helpful for CLI applications like CI services.

      sudo apt update 
      sudo apt install -y unzip xvfb libxi6 libgconf-2-4 
      

      Also, install Java on your system. Let’s install Oracle Java 8 on your system or use the below command to install OpenJDK.

      sudo apt install default-jdk 
      

      Step 2 – Install Google Chrome

      Now install Latest Google chrome package on your system using the below list commands. Google chrome headless feature opens multipe doors for the automation.

      sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add 
      sudo bash -c "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google-chrome.list" 
      sudo apt -y update 
      sudo apt -y install google-chrome-stable 
      

      Step 3 – Installing ChromeDriver

      You are also required to set up ChromeDriver on your system. ChromeDriver is a standalone server that implements WebDriver’s wire protocol for Chromium. The WebDriver is an open-source tool for the automated testing of web apps across multiple browsers.

      Find out the Google chrome version installed on your system.

      google-chrome --version 
      
      Output
      Google Chrome 94.0.4606.71

      Next, visit the Chromedriver download page and download the matching version of chromedriver on your system.

      In my case, Google Chrome 94 is running on my system. So download the following file. You must make sure to download the correct version of a file:

      wget https://chromedriver.storage.googleapis.com/94.0.4606.61/chromedriver_linux64.zip 
      unzip chromedriver_linux64.zip 
      

      You can find the latest ChromeDriver on its official download page. Now execute below commands to configure ChromeDriver on your system.

      sudo mv chromedriver /usr/bin/chromedriver 
      sudo chown root:root /usr/bin/chromedriver 
      sudo chmod +x /usr/bin/chromedriver 
      

      Step 4 – Download Required Jar Files

      The Selenium Server is required to run Remote Selenium WebDrivers. You need to download the Selenium standalone server jar file using the below commands or visit here to find the latest version of Jar file.

      wget https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar 
      mv selenium-server-standalone-3.141.59.jar selenium-server-standalone.jar 
      

      Also, download the testng-6.8.7.jar file to your system.

      wget http://www.java2s.com/Code/JarDownload/testng/testng-6.8.7.jar.zip 
      unzip testng-6.8.7.jar.zip 
      

      Step 5 – Start Chrome via Selenium Server

      Your server setup is ready. Start Chrome via a standalone selenium server using the Xvfb utility.

      Run Chrome via Selenium Server

      xvfb-run java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar selenium-server-standalone.jar 
      

      Use -debug option at end of the command to start the server in debug mode.

      You can also Start Headless ChromeDriver by typing the below command on the terminal.

      chromedriver --url-base=/wd/hub 
      

      Your Selenium server is now running with Chrome. Use this server to run your test cases written in Selenium using the Google Chrome web browser. The next step is an optional step and doesn’t depend on Step 5.

      Step 6 – Sample Java Program (Optional)

      This is an optional step. It describes running a single test case using a Selenium standalone server and ChromeDriver. Let’s create a Java program using the Selenium server and Chrome Driver. This Java program will open a specified website URL and check if a defined string is present on the webpage or not.

      Create a Java program by editing a file in a text editor.

      vim TecAdminSeleniumTest.java 
      

      Add the below content to the file.

      import java.io.IOException;
      
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.chrome.ChromeOptions;
      import org.openqa.selenium.chrome.ChromeDriver;
      import org.testng.annotations.Test;
      
      public class TecAdminSeleniumTest {
      
              public static void main(String[] args) throws IOException, InterruptedException {
                      System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
                      ChromeOptions chromeOptions = new ChromeOptions();
                      chromeOptions.addArguments("--headless");
                      chromeOptions.addArguments("--no-sandbox");
      
                      WebDriver driver = new ChromeDriver(chromeOptions);
      
                      driver.get("https://google.com");
      
                      Thread.sleep(1000);
      
                      if (driver.getPageSource().contains("I'm Feeling Lucky")) {
                              System.out.println("Pass");
                      } else {
                              System.out.println("Fail");
                      }
                      driver.quit();
              }
      }

      You can change the URL “https://google.com” with any other URL of your choice, Then also change the search string like “I’m Feeling Lucky” used in the above Java program. Save your java program and execute it. First, you need to set the Java CLASSPATH environment variable including the selenium-server-standalone.jar and testng-6.8.7.jar. Then compile the java program and run it.

      export CLASSPATH=".:selenium-server-standalone.jar:testng-6.8.7.jar" 
      javac TecAdminSeleniumTest.java 
      java TecAdminSeleniumTest 
      

      You will see the results below. If the defined search string is found, You will get the message “Pass” and if the string is not found on the webpage, you will get the “Fail” message on the screen.

      Selenium test case results

      The post How to Setup Selenium with ChromeDriver on Ubuntu 22.04, 20.04 & 18.04 appeared first on TecAdmin.

      ]]>
      https://tecadmin.net/setup-selenium-chromedriver-on-ubuntu/feed/ 42