Search

Just Another Tech Blog

A mind is like a parachute. It doesn't work if it is not open.

How To Install and Use Docker on Ubuntu 16.04


Prerequisites

To follow this tutorial, you will need the following:

  • 64-bit Ubuntu 16.04 server
  • Non-root user with sudo privileges

Note: Docker requires a 64-bit version of Ubuntu as well as a kernel version equal to or greater than 3.10. The default 64-bit Ubuntu 16.04 server meets these requirements.

All the commands in this tutorial should be run as a non-root user. If root access is required for the command, it will be preceded by sudo.

Step 1 — Installing Docker

The Docker installation package available in the official Ubuntu 16.04 repository may not be the latest version. To get the latest and greatest version, install Docker from the official Docker repository. This section shows you how to do just that.

First, add the GPG key for the official Docker repository to the system:

  • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker repository to APT sources:

  • sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Next, update the package database with the Docker packages from the newly added repo:

  • sudo apt-get update

Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:

  • apt-cache policy docker-ce

You should see output similar to the follow:
Output of apt-cache policy docker-ce

docker-ce:
  Installed: (none)
  Candidate: 17.03.1~ce-0~ubuntu-xenial
  Version table:
     17.03.1~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.03.0~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

Notice that docker-ce is not installed, but the candidate for installation is from the Docker repository for Ubuntu 16.04. The docker-ce version number might be different.

Finally, install Docker:

  • sudo apt-get install -y docker-ce

Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:

  • sudo systemctl status docker

The output should be similar to the following, showing that the service is active and running:
Output:

● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2016-05-01 06:53:52 CDT; 1 weeks 3 days ago
     Docs: https://docs.docker.com
 Main PID: 749 (docker)

Installing Docker now gives you not just the Docker service (daemon) but also the docker command line utility, or the Docker client. We’ll explore how to use the docker command later in this tutorial.

Step 2 — Executing the Docker Command Without Sudo (Optional)

By default, running the docker command requires root privileges — that is, you have to prefix the command with sudo. It can also be run by a user in the docker group, which is automatically created during the installation of Docker. If you attempt to run the docker command without prefixing it with sudo or without being in the docker group, you’ll get an output like this:
Output:

docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.

If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group:

  • sudo usermod -aG docker ${USER}

To apply the new group membership, you can log out of the server and back in, or you can type the following:

  • su - ${USER}

You will be prompted to enter your user’s password to continue. Afterwards, you can confirm that your user is now added to the docker group by typing:

  • id -nG

Output:

sammy sudo docker

If you need to add a user to the docker group that you’re not logged in as, declare that username explicitly using:

  • sudo usermod -aG docker username

The rest of this article assumes you are running the docker command as a user in the docker user group. If you choose not to, please prepend the commands with sudo.

Step 3 — Using the Docker Command

With Docker installed and working, now’s the time to become familiar with the command line utility. Using docker consists of passing it a chain of options and commands followed by arguments. The syntax takes this form:

  • docker [option] [command] [arguments]

To view all available subcommands, type:

  • docker

As of Docker 1.11.1, the complete list of available subcommands includes:

Output:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on a container or image
kill Kill a running container
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
network Manage Docker networks
pause Pause all processes within a container
port List port mappings or a specific mapping for the CONTAINER
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart a container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop a running container
tag Tag an image into a repository
top Display the running processes of a container
unpause Unpause all processes within a container
update Update configuration of one or more containers
version Show the Docker version information
volume Manage Docker volumes
wait Block until a container stops, then print its exit code

To view the switches available to a specific command, type:

  • docker docker-subcommand --help

To view system-wide information about Docker, use:

  • docker info

Step 4 — Working with Docker Images

Docker containers are run from Docker images. By default, it pulls these images from Docker Hub, a Docker registry managed by Docker, the company behind the Docker project. Anybody can build and host their Docker images on Docker Hub, so most applications and Linux distributions you’ll need to run Docker containers have images that are hosted on Docker Hub.

To check whether you can access and download images from Docker Hub, type:

  • docker run hello-world

The output, which should include the following, should indicate that Docker in working correctly:

Output:

Hello from Docker.
This message shows that your installation appears to be working correctly.
...

You can search for images available on Docker Hub by using the docker command with the searchsubcommand. For example, to search for the Ubuntu image, type:

  • docker search ubuntu

The script will crawl Docker Hub and return a listing of all images whose name match the search string. In this case, the output will be similar to this:

Output:

NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating s... 3808 [OK]
ubuntu-upstart Upstart is an event-based replacement for ... 61 [OK]
torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 25 [OK]
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 24 [OK]
ubuntu-debootstrap debootstrap --variant=minbase --components... 23 [OK]
nickistre/ubuntu-lamp LAMP server on Ubuntu 6 [OK]
nickistre/ubuntu-lamp-wordpress LAMP on Ubuntu with wp-cli installed 5 [OK]
nuagebec/ubuntu Simple always updated Ubuntu docker images... 4 [OK]
nimmis/ubuntu This is a docker images different LTS vers... 4 [OK]
maxexcloo/ubuntu Docker base image built on Ubuntu with Sup... 2 [OK]
admiringworm/ubuntu Base ubuntu images based on the official u... 1 [OK]

 

In the OFFICIAL column, OK indicates an image built and supported by the company behind the project. Once you’ve identified the image that you would like to use, you can download it to your computer using the pull subcommand, like so:

  • docker pull ubuntu

After an image has been downloaded, you may then run a container using the downloaded image with the run subcommand. If an image has not been downloaded when docker is executed with the runsubcommand, the Docker client will first download the image, then run a container using it:

  • docker run ubuntu

To see the images that have been downloaded to your computer, type:

  • docker images

The output should look similar to the following:

Output:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              c5f1cf30c96b        7 days ago          120.8 MB
hello-world         latest              94df4f0ce8a4        2 weeks ago         967 B

As you’ll see later in this tutorial, images that you use to run containers can be modified and used to generate new images, which may then be uploaded (pushed is the technical term) to Docker Hub or other Docker registries.

Step 5 — Running a Docker Container

The hello-world container you ran in the previous is an example of a container that runs and exits, after emitting a test message. Containers, however, can be much more useful than that, and they can be interactive. After all, they are similar to virtual machines, only more resource-friendly.

As an example, let’s run a container using the latest image of Ubuntu. The combination of the -i and -tswitches gives you interactive shell access into the container:

  • docker run -it ubuntu

Your command prompt should change to reflect the fact that you’re now working inside the container and should take this form:

Output:

root@d9b100f2f636:/#

Important: Note the container id in the command prompt. In the above example, it is d9b100f2f636.

Now you may run any command inside the container. For example, let’s update the package database inside the container. No need to prefix any command with sudo, because you’re operating inside the container with root privileges:

  • apt-get update

Then install any application in it. Let’s install NodeJS, for example.

  • apt-get install -y nodejs

Step 6 — Listing Docker Containers

After using Docker for a while, you’ll have many active (running) and inactive containers on your computer. To view the active ones, use:

  • docker ps

You will see output similar to the following:

Output:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
f7c79cc556dd        ubuntu              "/bin/bash"         3 hours ago         Up 3 hours                              silly_spence

To view all containers — active and inactive, pass it the -a switch:

  • docker ps -a

To view the latest container you created, pass it the -l switch:

  • docker ps -l

Stopping a running or active container is as simple as typing:

  • docker stop container-id

The container-id can be found in the output from the docker ps command.

Step 7 — Committing Changes in a Container to a Docker Image

When you start up a Docker image, you can create, modify, and delete files just like you can with a virtual machine. The changes that you make will only apply to that container. You can start and stop it, but once you destroy it with the docker rm command, the changes will be lost for good.

This section shows you how to save the state of a container as a new Docker image.

After installing nodejs inside the Ubuntu container, you now have a container running off an image, but the container is different from the image you used to create it.

To save the state of the container as a new image, first exit from it:

  • exit

Then commit the changes to a new Docker image instance using the following command.

Note: If you run an image and made some modification and now want to save the modified image locally then follow the below steps:

  • use docker ps -a command to see the container listing and copy the container id.
  • now, use:
docker commit <container-id> <new-image-name>

It will save the modified modified image as the <new-image-name>. You can see the new modified image using the docker images command.

The -m switch is for the commit message that helps you and others know what changes you made, while -a is used to specify the author. The container ID is the one you noted earlier in the tutorial when you started the interactive docker session. Unless you created additional repositories on Docker Hub, the repository is usually your Docker Hub username:

  • docker commit -m "What did you do to the image" -a "Author Name" container-id repository new_image_name

For example:

  • docker commit -m "added node.js" -a "Sunday Ogwu-Chinuwa" d9b100f2f636 finid/ubuntu-nodejs

Note: When you commit an image, the new image is saved locally, that is, on your computer. Later in this tutorial, you’ll learn how to push an image to a Docker registry like Docker Hub so that it may be assessed and used by you and others.

After that operation has completed, listing the Docker images now on your computer should show the new image, as well as the old one that it was derived from:

  • docker images

The output should be similar to this:

Output:

finid/ubuntu-nodejs      latest              62359544c9ba        50 seconds ago      206.6 MB
ubuntu              latest              c5f1cf30c96b        7 days ago          120.8 MB
hello-world         latest              94df4f0ce8a4        2 weeks ago         967 B

In the above example, ubuntu-nodejs is the new image, which was derived from the existing ubuntu image from Docker Hub. The size difference reflects the changes that were made. And in this example, the change was that NodeJS was installed. So next time you need to run a container using Ubuntu with NodeJS pre-installed, you can just use the new image. Images may also be built from what’s called a Dockerfile. But that’s a very involved process that’s well outside the scope of this article.

 

Step 8 — Pushing Docker Images to a Docker Repository

The next logical step after creating a new image from an existing image is to share it with a select few of your friends, the whole world on Docker Hub, or other Docker registry that you have access to. To push an image to Docker Hub or any other Docker registry, you must have an account there.

This section shows you how to push a Docker image to Docker Hub. To learn how to create your own private Docker registry, check out How To Set Up a Private Docker Registry on Ubuntu 14.04.

To create an account on Docker Hub, register at Docker Hub. Afterwards, to push your image, first log into Docker Hub. You’ll be prompted to authenticate:

  • docker login -u docker-registry-username

If you specified the correct password, authentication should succeed. Then you may push your own image using:

  • docker push docker-registry-username/docker-image-name

It will take sometime to complete, and when completed, the output will similar to the following:

Output:

The push refers to a repository [docker.io/finid/ubuntu-nodejs]
e3fbbfb44187: Pushed
5f70bf18a086: Pushed
a3b5c80a4eba: Pushed
7f18b442972b: Pushed
3ce512daaf78: Pushed
7aae4540b42d: Pushed

...

After pushing an image to a registry, it should be listed on your account’s dashboard,

If a push attempt results in an error of this sort, then you likely did not log in:

Output:

The push refers to a repository [docker.io/finid/ubuntu-nodejs]
e3fbbfb44187: Preparing
5f70bf18a086: Preparing
a3b5c80a4eba: Preparing
7f18b442972b: Preparing
3ce512daaf78: Preparing
7aae4540b42d: Waiting
unauthorized: authentication required

Log in, then repeat the push attempt.

Conclusion

There’s a whole lot more to Docker than has been given in this article, but this should be enough to getting you started working with it on Ubuntu 16.04. Like most open source projects, Docker is built from a fast-developing codebase, so make a habit of visiting the project’s blog page for the latest information.

Please Note: The content of this page is collected from the https://www.digitalocean.com site for my personal reference in future use. Therefore, all the credit and copyrights goes to the mentioned site

Fix Docker’s networking DNS config


Sometimes, Docker‘s internet connectivity won’t be working properly, which can lead to a number of obscure errors with your applications. In my experience, this is usually because DNS lookups are failing in Docker images.

If you know it’s a DNS problem and you’re in a hurry, jump straight to the system-wide solution.

Is DNS the problem?

Fortunately it’s easy to test Docker’s DNS.

First, check that basic internet connectivity is working by pinging a public IP address. It should succeed, giving you output similar to this:

$ docker run busybox ping -c 1 192.203.230.10  # Ping a London-based NASA root nameserver
PING 192.203.230.10 (192.203.230.10): 56 data bytes
64 bytes from 192.203.230.10: seq=0 ttl=53 time=113.866 ms

--- 192.203.230.10 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 113.866/113.866/113.866 ms

But now try resolving the domain google.com:

$ docker run busybox nslookup google.com
Server:    8.8.8.8
Address 1: 8.8.8.8
nslookup: can't resolve 'google.com'

If it fails as shown above then there is a problem resolving DNS.

Why?

By default, if Docker can’t find a DNS server locally defined in your /etc/resolv.conf file, containers will default to using Google’s public DNS server8.8.8.8, to resolve DNS.

In some networks, like Canonical’s London office network where I work, the administrators intentionally block the use of public DNS servers to encourage people to use the network’s own DNS server.

In this case, Docker containers using the default configuration won’t be able to resolve DNS, rendering the internet effectively unuseable from within those containers.

I’ve filed a bug about this issue, although I don’t yet know when or if it might be addressed.

The quick fix: Overriding Docker’s DNS

Fortunately, it’s fairly easy to directly run a docker container with a custom DNS server.

Discover the address of your DNS server

You can find out what network’s DNS server from within Ubuntu as follows:

$ nmcli dev show | grep 'IP4.DNS'
IP4.DNS[1]:                             10.0.0.2

Run Docker with the new DNS server

To run a docker container with this DNS server, provide the --dns flag to the run command. For example, let’s run the command we used to check if DNS is working:

$ docker run --dns 10.0.0.2 busybox nslookup google.com
Server:    10.0.0.2
Address 1: 10.0.0.2
Name:      google.com
Address 1: 2a00:1450:4009:811::200e lhr26s02-in-x200e.1e100.net
Address 2: 216.58.198.174 lhr25s10-in-f14.1e100.net

And that’s what success looks like.

The permanent system-wide fix

The above solution is all very well if you’re only temporarily inside a restrictive network and you only need to run containers directly.

However, most of the time you’ll want this to work by default and keep working on your system, and for any other programs that rely on Docker.

Update the Docker daemon

To achieve this, you need to change the DNS settings of the Docker daemon. You can set the default options for the docker daemon by creating a daemon configuration file at /etc/docker/daemon.json.

You should create this file with the following contents to set two DNS, firstly your network’s DNS server, and secondly the Google DNS server to fall back to in case that server isn’t available:

/etc/docker/daemon.json:

{
    "dns": ["10.0.0.2", "8.8.8.8"]
}

Then restart the docker service:

sudo service docker restart

Testing the fix

Now you should be able to ping google.com successfully from any Docker container without explicitly overriding the DNS server, e.g.:

$ docker run busybox nslookup google.com
Server:    10.0.0.2
Address 1: 10.0.0.2
Name:      google.com
Address 1: 2a00:1450:4009:811::200e lhr26s02-in-x200e.1e100.net
Address 2: 216.58.198.174 lhr25s10-in-f14.1e100.net

Please Note: This post is collected from https://robinwinslow.uk site. I am just posting the solution here as my future reference. All the credit and copyrights goes to the mentioned site.

How to Bypass Adblock Detection on Websites that Bombard You With Ads


Easy One-click Solution to Bypass Ad Block Detection

The easiest way you can bypass ad block detection on a website is by disabling JavaScript using the Site Info option on the browser. Just click on the Site Info icon as shown in the screen shot and disable the JavaScript option.

java-script

Bypass Adblock Using Tamper Monkey Script

If there are more than one website you wish to bypass, than installing anti-adblock killer makes more sense. The UserScript helps you keep your ad-blocker active when you visit a website even when it asks you to disable it. As this is a script, you will have to install Greasemonkey on Firefox or Tampermonkey for Opera or Chrome. Once these add-ons are installed, you will have to download this JS file and add it to the Tampermonkey extension.

Selection_015

Now you do not need to disable the adblocker on any site, instead the JS script will prevent that site’s anti-adblocker script and let you browse the site smoothly.

Happy browsing!!

Source: http://www.guidingtech.com/60376/bypass-ad-block-detection-sites/

How To Add Robot Framework Syntax in Sublime Text and VIM editor


By default, files for the Robot Framework do not show any syntax on Sublime Text or VIM, with some tweaks we can add Robot Framework syntax.

For Sublime Text 2:

Open Sublime Text 2 and click Preferences -> Browse Packages to open the packages directory. Then create a directory named Robot Framework containing the contents of the following repository:

https://github.com/seeamkhan/sublime-robot-plugin

Note: The contents of the repository should be directly under the Robot Framework directory.

Now close the Sublime Text 2 editor if it’s already been opened and then open a file with Robot Framework syntax, the syntax should be now visible like below:

Selection_012

For VIM Text Editor:

Clone the git repository in any place:

git clone https://github.com/seeamkhan/robotframework-vim

Go to the content directory:

cd robotframework-vim

Make sure the directory ~/.vim/ already exist for the current user, if not then create the directory:

mkdir ~/.vim

Now copy all the contents to ~/.vim/ location:

cp -R * ~/.vim/

Now open any files with Robot Framework syntax in the VIM editor, the syntax should be visible like below:

Selection_014

Prepare CentOS 6.x or 7.x Server for Selenium


We need to install the following things in the server to run the Python test scripts after WordPress auto update:

  1. Need to be installed Python 2.6.x or 2.7.x
  2. Install WP CLI, see detail: http://wp-cli.org/
  3. Install pip:For RHEL 6.x and CentOS 6.x (x86_64)
    rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

    For RHEL 6.x and CentOS 6.x (i386)

    rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

    Now install pip with yum command:

    yum install -y python-pip

    If you can not install pip be following the above steps then try the below steps:

    curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
    python get-pip.py
    
  4. Install Selenium:
    pip install selenium
    
  5. Install python-detenv:
    pip install python-dotenv
    
  6. Install python requests library:

    pip install requests
  7. Download Phantomjsfrom:http://phantomjs.org/download.html
  8. Copy Phantomjs to /usr/local/share/:
    cp -f phantomjs /usr/local/share/phantomjs

    Note: Keep the phantomjs nonexecutable while the wp-auto-update will run the script will make it executable and make it nonexecutable once it’s done.

  9. Make symlinks of Phantomjs:
    ln -s /usr/local/share/phantomjs /usr/local/bin/phantomjs
    ln -s /usr/local/share/phantomjs /usr/bin/phantomjs
    
  10. Install additional dependency for Phantomjs:
    yum install freetype
    yum install fontconfig

How to setup network after RHEL/CentOS 7 minimal installation


After installing RHEL/CentOS 7 minimal, You may not able to connect network in that machine. This will happen because Ethernet interfaces are not enabled by default.
This guide explain you to setup network on RHEL/CentOS 7.

Setup network on CentOS 7 minimal

First, type “nmcli d” command in your terminal for quick list ethernet card installed on your machine:

"nmcli d" command output

Type “nmtui” command in your terminal to open Network manager. After opening Network manager chose “Edit connection” and press Enter (Use TAB button for choosing options).

CentOS_7 Network manager screen

Now choose you network interfaces and click “Edit

Edit your network interfaces

DHCP configuration

Choose “Automatic” in IPv4 CONFIGURATION and check Automatically connect check box and press OK and quit from Network manager.

Set ip adress using DHCP

Reset network services:

service network restart

Now your server will get IP Address from DHCP .

CentOS 7 check ip address

 Source: https://lintut.com/how-to-setup-network-after-rhelcentos-7-minimal-installation/

XPath in Selenium WebDriver: Complete Tutorial


In Selenium automation, if the elements are not found by the general locators like id, class, name, etc. then XPath is used to find an element on the web page .

In this tutorial, we will learn about the xpath and different XPath expression to find the complex or dynamic elements, whose attributes changes dynamically on refresh or any operations.

What is XPath

XPath is defined as XML path. It is a syntax or language for finding any element on the web page using XML path expression. XPath is used to find the location of any element on a webpage using HTML DOM structure. The basic format of XPath is explained below with screen shot.

XPath in Selenium WebDriver: Complete Tutorial

Syntax for XPath:

XPath contains the path of the element situated at the web page. Standard syntax for creating XPath is.

Xpath=//tagname[@attribute='value']
  • // : Select current node.
  • Tagname: Tagname of the particular node.
  • @: Select attribute.
  • Attribute: Attribute name of the node.
  • Value: Value of the attribute.

To find the element on web pages accurately there are different types of locators:

XPath Locators Find different elements on web page
ID To find the element by ID of the element
Classname To find the element by Classname of the element
Name To find the element by name of the element
Link text To find the element by text of the link
XPath XPath required for finding the dynamic element and traverse between various elements of the web page
CSS path CSS path also locates elements having no name, class or ID.

Types of X-path

There are two types of XPath:

1) Absolute XPath .

2) Relative XPath .

Absolute XPath :

It is the direct way to find the element, but the disadvantage of the absolute XPath is that if there are any changes made in the path of the element then that XPath gets failed.

The key characteristic of XPath is that it begins with the single forward slash(/) ,which means you can select the element from the root node.

Below is the example of an absolute xpath expression of the element shown in the below screen.

Absolute xpath:

html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/div/h4[1]/b

XPath in Selenium WebDriver: Complete Tutorial

Relative xpath:

For Relative Xpath the path starts from the middle of the HTML DOM structure. It starts with the double forward slash (//), which means it can search the element anywhere at the webpage.

You can starts from the middle of the HTML DOM structure and no need to write long xpath.

Below is the example of a relative XPath expression of the same element shown in the below screen. This is the common format used to find element through a relative XPath.

Relative xpath: //*[@class='featured-box']//*[text()='Testing']

XPath in Selenium WebDriver: Complete Tutorial

What are XPath axes.

XPath axes search different nodes in XML document from current context node. XPath Axes are the methods used to find dynamic elements, which otherwise not possible by normal XPath method having no ID , Classname, Name, etc.

Axes methods are used to find those elements, which dynamically change on refresh or any other operations. There are few axes methods commonly used in Selenium Webdriver like child, parent, ancestor, sibling, preceding, self, etc.

Using XPath Handling complex & Dynamic elements in Selenium

1) Basic XPath:

XPath expression select nodes or list of nodes on the basis of attributes like ID , Name, Classname, etc. from the XML document as illustrated below.

Xpath=//input[@name='uid']

Here is a link to access the page http://demo.guru99.com/v1/

XPath in Selenium WebDriver: Complete Tutorial

Some more basic xpath expressions:

Xpath=//input[@type='text']				
Xpath=	//label[@id='message23']
Xpath=	//input[@value='RESET']
Xpath=//*[@class='barone']
Xpath=//a[@href='http://demo.guru99.com/']
Xpath= //img[@src='//cdn.guru99.com/images/home/java.png']

2) Contains() : Contains() is a method used in XPath expression. It is used when the value of any attribute changes dynamically, for example, login information.

The contain feature has an ability to find the element with partial text as shown in below example.

In this example, we tried to identify the element by just using partial text value of the attribute. In the below XPath expression partial value ‘sub’ is used in place of submit button. It can be observed that the element is found successfully.

Complete value of ‘Type’ is ‘submit’ but using only partial value ‘sub’.

Xpath=//*[contains(@type,'sub')]

Complete value of ‘name’ is ‘btnLogin’ but using only partial value ‘btn’.

Xpath=.//*[contains(@name,'btn')]

In the above expression, we have taken the ‘name’ as an attribute and ‘btn’ as an partial value as shown in the below screenshot. This will find 2 elements (LOGIN & RESET) as their ‘name’ attribute begins with ‘btn’.

XPath in Selenium WebDriver: Complete Tutorial

Similarly, in the below expression, we have taken the ‘id’ as an attribute and ‘message’ as a partial value. This will find 2 elements (‘User-ID must not be blank’ & ‘Password must not be blank’) as its ‘name’ attribute begins with ‘message’.

Xpath=//*[contains(@id,'message')]

XPath in Selenium WebDriver: Complete Tutorial

In the below expression, we have taken the “text” of the link as an attribute and ‘here’ as a partial value as shown in the below screenshot. This will find the link (‘here’) as it displays the text ‘here’.

Xpath=//*[contains(text(),'here')]
Xpath=//*[contains(@href,'guru99.com')]

XPath in Selenium WebDriver: Complete Tutorial

3) Using OR & AND:

In OR expression, two conditions are used, whether 1st condition OR 2nd condition should be true. It is also applicable if any one condition is true or maybe both. Means any one condition should be true to find the element.

In the below XPath expression, it identifies the elements whose single or both conditions are true.

Xpath=//*[@type='submit' OR @name='btnReset']

Highlighting both elements as “LOGIN ” element having attribute ‘type’ and “RESET” element having attribute ‘name’.

XPath in Selenium WebDriver: Complete Tutorial

In AND expression, two conditions are used, both conditions should be true to find the element. It fails to find element if any one condition is false.

Xpath=//input[@type='submit' AND @name='btnLogin']

In below expression, highlighting ‘LOGIN’ element as it having both attribute ‘type’ and ‘name’.

XPath in Selenium WebDriver: Complete Tutorial

4) Start-with function: Start-with function finds the element whose attribute value changes on refresh or any operation on the webpage. In this expression, match the starting text of the attribute is used to find the element whose attribute changes dynamically. You can also find the element whose attribute value is static (not changes).

For example -: Suppose the ID of particular element changes dynamically like:

Id=” message12″

Id=” message345″

Id=” message8769″

and so on.. but the initial text is same. In this case, we use Start-with expression.

In the below expression, there are two elements with an id starting “message”(i.e., ‘User-ID must not be blank’ & ‘Password must not be blank’). In below example, XPath finds those element whose ‘ID’ starting with ‘message’.

Xpath=//label[starts-with(@id,'message')]

XPath in Selenium WebDriver: Complete Tutorial

5) Text(): In this expression, with text function, we find the element with exact text match as shown below. In our case, we find the element with text “UserID”.

Xpath=//td[text()='UserID']

XPath in Selenium WebDriver: Complete Tutorial

6) XPath axes methods: These XPath axes methods are used to find the complex or dynamic elements. Below we will see some of these methods.

For illustrating these XPath axes method, we will use the Guru99 bank demo site.

a) Following: Selects all elements in the document of the current node( ) [ UserID input box is the current node] as shown in the below screen.

Xpath=//*[@type='text']//following::input

XPath in Selenium WebDriver: Complete Tutorial

There are 3 “input” nodes matching by using “following” axis- password, login and reset button. If you want to focus on any particular element then you can use the below XPath method:

Xpath=//*[@type='text']//following::input[1]

You can change the XPath according to the requirement by putting [1],[2]…………and so on.

With the input as ‘1’, the below screen shot finds the particular node that is ‘Password’ input box element.

XPath in Selenium WebDriver: Complete Tutorial

b) Ancestor: The ancestor axis selects all ancestors element (grandparent, parent, etc.) of the current node as shown in the below screen.

In the below expression, we are finding ancestors element of the current node(“ENTERPRISE TESTING” node).

Xpath=//*[text()='Enterprise Testing']//ancestor::div

XPath in Selenium WebDriver: Complete Tutorial

There are 13 “div” nodes matching by using “ancestor” axis. If you want to focus on any particular element then you can use the below XPath, where you change the number 1, 2 as per your requirement:

Xpath=//*[text()='Enterprise Testing']//ancestor::div[1]

You can change the XPath according to the requirement by putting [1], [2]…………and so on.

c) Child : Selects all children elements of the current node (Java) as shown in the below screen.

Xpath=//*[@id='java_technologies']/child::li

XPath in Selenium WebDriver: Complete Tutorial

There are 71 “li” nodes matching by using “child” axis. If you want to focus on any particular element then you can use the below xpath:

Xpath=//*[@id='java_technologies']/child::li[1]

You can change the xpath according to the requirement by putting [1],[2]…………and so on.

d) Preceding: Select all nodes that come before the current node as shown in the below screen.

In the below expression, it identifies all the input elements before “LOGIN” button that is Userid and password input element.

Xpath=//*[@type='submit']//preceding::input

XPath in Selenium WebDriver: Complete Tutorial

There are 2 “input” nodes matching by using “preceding” axis. If you want to focus on any particular element then you can use the below XPath:

Xpath=//*[@type='submit']//preceding::input[1]

You can change the xpath according to the requirement by putting [1],[2]…………and so on.

e) Following-sibling: Select the following siblings of the context node. Siblings are at the same level of the current node as shown in the below screen. It will find the element after the current node.

 xpath=//*[@type='submit']//following-sibling::input

XPath in Selenium WebDriver: Complete Tutorial

One input nodes matching by using “following-sibling” axis.

f) Parent: Selects the parent of the current node as shown in the below screen.

Xpath=//*[@id='rt-feature']//parent::div

XPath in Selenium WebDriver: Complete Tutorial

There are 65 “div” nodes matching by using “parent” axis. If you want to focus on any particular element then you can use the below XPath:

Xpath=//*[@id='rt-feature']//parent::div[1]

You can change the XPath according to the requirement by putting [1],[2]…………and so on.

g) Self: Selects the current node or ‘self’ means it indicates the node itself as shown in the below screen.

XPath in Selenium WebDriver: Complete Tutorial

One node matching by using “self ” axis. It always finds only one node as it represents self-element.

Xpath =//*[@type='password']//self::input

h) Descendant: Selects the descendants of the current node as shown in the below screen.

In the below expression, it identifies all the element descendants to current element ( ‘Main body surround’ frame element) which means down under the node (child node , grandchild node, etc.).

Xpath=//*[@id='rt-feature']//descendant::a

XPath in Selenium WebDriver: Complete Tutorial

There are 12 “link” nodes matching by using “descendant” axis. If you want to focus on any particular element then you can use the below XPath:

Xpath=//*[@id='rt-feature']//descendant::a[1]

You can change the XPath according to the requirement by putting [1],[2]…………and so on.

Summary:

XPath is required to find an element on the web page as to do an operation on that particular element.

  • There are two types of XPath:
    • Absolute XPath
    • Relative XPath
  • XPath Axes are the methods used to find dynamic elements, which otherwise not possible to find by normal XPath method
  • XPath expression select nodes or list of nodes on the basis of attributes like ID , Name, Classname, etc. from the XML document .
Source: http://www.guru99.com/xpath-selenium.html

Installing CMU-Sphinx on Ubuntu


Some Background

I recently installed Ubuntu 14.04 on my Lenovo Yoga, and it’s time to reinstall SPHINX.

When I installed SPHINX for the first time in September 2015, it was not a fun experience. I originally followed the instructions on CMU’s website, but I couldn’t seem to get it right. I tried a number of different approaches, using different blogs as guides, but I got nowhere. I first tried downloading Pocketsphinx, Sphinxtrain, Sphinxbase and Sphinx4 from CMU’s downloads page, but that didn’t work. I also tried installing the version hosted on SourceForge, but no luck there either. I finally decided to try cloning and installing the version on GitHub, and that seemed to do the trick. However, at the end of this post I show how to install CMUCLMTK from SourceForge, because they don’t have it on GitHub.

So, I’m going to go through installation process again here.

First, in case it’s relevant for others I’m going to show a little info about my current setup.

josh@yoga:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 14.04.3 LTS
Release:	14.04
Codename:	trusty

You can see the exact kernel on my version of Ubuntu below:

josh@yoga:~$ uname -a
Linux yoga 3.19.0-43-generic #49~14.04.1-Ubuntu SMP Thu Dec 31 15:44:49 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Installing Dependencies

To install on Ubuntu (or any other unix-like system), we first need to install a few dependencies. Here’s the list:

Name Homepage Description
gcc GNU Compiler Collection GCC development is a part of the GNU Project, aiming to improve the compiler used in the GNU system including the GNU/Linux variant.
automake Automake Tool for generating GNU Standards-compliant Makefiles.
autoconf Autoconf Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages.
libtool GNU Libtool GNU libtool is a generic library support script. Libtool hides the complexity of using shared libraries behind a consistent, portable interface.
bison GNU Bison Bison is a general-purpose parser generator that converts an annotated context-free grammar into a deterministic LR or generalized LR (GLR) parser employing LALR(1) parser tables.
swig SWIG SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages.
python-dev Python Development Package Header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications.
libpulse-dev PulseAudio Development Package Headers and libraries for developing applications that access a PulseAudio sound server via PulseAudio’s native interface.

Here’s the command to get everything at once:

sudo apt-get install gcc automake autoconf libtool bison swig python-dev libpulse-dev

Installing CMU-SPHINX

Installing sphinxbase

Whether you’re using pocketsphinx or sphinx4, you’re going to need to install sphinxbase first.

The README for the sphinxbase repository says:

This package contains the basic libraries shared by the CMU Sphinx trainer and all the Sphinx decoders (Sphinx-II, Sphinx-III, and PocketSphinx), as well as some common utilities for manipulating acoustic feature and audio files.

To get sphinxbase running, we need to clone the repository from GitHub and then run a few commands to configure and install it in the right spot.

I usually make a folder on my desktop to store the source code, and then when it’s all been installed you can just throw away all those extra files.

So, first we need to get to the Desktop, make a new directory and cd into it.

josh@yoga:~$ cd Desktop/
josh@yoga:~/Desktop$ mkdir sphinx-source
josh@yoga:~/Desktop$ cd sphinx-source/
josh@yoga:~/Desktop/sphinx-source$ 

Now we can clone the source from GitHub, and you should get something like this:

josh@yoga:~/Desktop/sphinx-source$ git clone https://github.com/cmusphinx/sphinxbase.git
Cloning into 'sphinxbase'...
remote: Counting objects: 10302, done.
remote: Total 10302 (delta 0), reused 0 (delta 0), pack-reused 10302
Receiving objects: 100% (10302/10302), 8.95 MiB | 1.46 MiB/s, done.
Resolving deltas: 100% (8092/8092), done.
Checking connectivity... done.

Now can see that our once empty dir sphinx-source now has a new directory, sphinxbase:

josh@yoga:~/Desktop/sphinx-source$ la
sphinxbase

Let’s look at what’s inside this new dir, sphinxbase:

josh@yoga:~/Desktop/sphinx-source$ la sphinxbase/
AUTHORS       doc      indent.sh  Makefile.am  README.md         src   win32
autogen.sh    .git     LICENSE    NEWS         sphinxbase.pc.in  swig
configure.ac  include  m4         README       sphinxbase.sln    test

Now we need to run the autogen.sh shell script you can see in the sphinxbase directory. This will generate our Makefiles and other important scripts for compiling and installing. We’re going to get a long output here, so I only show some of it here:

josh@yoga:~/Desktop/sphinx-source$ cd sphinxbase/
josh@yoga:~/Desktop/sphinx-source/sphinxbase$ ./autogen.sh
**Warning**: I am going to run `configure' with no arguments.
If you wish to pass any to it, please specify them on the
`./autogen.sh' command line.

processing .
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
Running aclocal  ...
Running autoheader...
Running automake --foreign --copy  ...
configure.ac:12: installing './compile'
                        .
                        .
                        .
config.status: creating test/regression/testfuncs.sh
config.status: creating test/regression/Makefile
config.status: creating swig/Makefile
config.status: creating swig/python/Makefile
config.status: creating include/config.h
config.status: creating include/sphinx_config.h
config.status: executing depfiles commands
config.status: executing libtool commands
Now type `make' to compile the package.

Before we charge right ahead to compilation with the make command, lets take a look at what new files were generated from running autogen.sh.

josh@yoga:~/Desktop/sphinx-source/sphinxbase$ la
aclocal.m4      config.log     doc         LICENSE      missing        sphinxbase.pc.in  win32
AUTHORS         config.status  .git        ltmain.sh    NEWS           sphinxbase.sln    ylwrap
autogen.sh      config.sub     include     m4           py-compile     src
autom4te.cache  configure      indent.sh   Makefile     README         swig
compile         configure.ac   install-sh  Makefile.am  README.md      test
config.guess    depcomp        libtool     Makefile.in  sphinxbase.pc  test-driver

You can see that we now have the scripts needed for compiling, configuring, and installing sphinxbase. Now we can run make to do our installation. As nicely summarized on Wikipedia, Make is a utility that automatically builds executable programs and libraries from source code by reading files called Makefiles which specify how to derive the target program.”

When you run the make command without any arguments (still in the local version of the cloned sphinxbase repository), you will get a long output that ends something like this:

josh@yoga:~/Desktop/sphinx-source/sphinxbase$ make
                        .
                        .
                        .
libtool: link: (cd ".libs" && rm -f "_sphinxbase.so.0" && ln -s "_sphinxbase.so.0.0.0" "_sphinxbase.so.0")
libtool: link: (cd ".libs" && rm -f "_sphinxbase.so" && ln -s "_sphinxbase.so.0.0.0" "_sphinxbase.so")
libtool: link: ar cru .libs/_sphinxbase.a  _sphinxbase_la-sphinxbase_wrap.o
libtool: link: ranlib .libs/_sphinxbase.a
libtool: link: ( cd ".libs" && rm -f "_sphinxbase.la" && ln -s "../_sphinxbase.la" "_sphinxbase.la" )
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig/python'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxbase'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase'

The next step is the last step. Run the command sudo make install. Root permission is important, because otherwise you will get some error without any Permision Denied warning.

You will see a good amount of output with some sections that look like this:

josh@yoga:~/Desktop/sphinx-source/sphinxbase$ sudo make install
                        .
                        .
                        .
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                        .
                        .
                        .
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib/python2.7/dist-packages/sphinxbase

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                        .
                        .
                        .
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxbase'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxbase'
make[2]: Nothing to be done for `install-exec-am'.
 /bin/mkdir -p '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 sphinxbase.pc '/usr/local/lib/pkgconfig'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase'

That’s it! You should have successfully installed sphinxbase. To check if you’ve actually installed it, just go to the terminal and do a tab-completion for sphinx_. You will see all the options of what you’ve just installed.

josh@yoga:~$ sphinx_
sphinx_cepview     sphinx_fe          sphinx_lm_convert  sphinx_pitch
sphinx_cont_seg    sphinx_jsgf2fsg    sphinx_lm_eval

At this point, if you try to run any one of these by entering it at the command line, you get an error:

josh@yoga:~$ sphinx_lm_convert
sphinx_lm_convert: error while loading shared libraries: libsphinxbase.so.3: cannot open shared object file: No such file or directory

This error has been answered by Nikolay Shmyrev on stackoverflow already, and the reason for this error is the following:

This error means that system fails to find the shared library in the location where it is installed. Most likely you installed it with default prefix /usr/local/lib which is not included into the library search path.

There’s a few ways to solve this problem. You may have come across this one which doesn’t work well:

josh@yoga:~$ export LD_LIBRARY_PATH=/usr/local/lib

The problem is, this solution will work for as long as you’re in the same session in your terminal. When you logout and log back in, you will have to reset the variable again.

Rather, we can edit the file /etc/ld.so.conf so we always look into the right directory when we need to. If you take a look at the Linux Programmer’s Manual you find the following description:

/etc/ld.so.conf: File containing a list of directories, one per line, in which to search for libraries.

So, this is the right place to make a change.

If you take a look into the config file right now, you will probably just see one line:

josh@yoga:~$ cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf

We want to add /usr/local/lib to the file. So, you can use nano to open it up, and add a new line that just says /usr/local/lib. That’s it. Don’t delete anything else or add anything else or you might get some headaches.

josh@yoga:~$ sudo nano /etc/ld.so.conf

If you’ve added that new line in via nano, you should see something like this:

screenshot

Now save the modified file (CTRL+o) and exit (CTRL+x).

Re-configure with the following command:

josh@yoga:~$ sudo ldconfig

Now you can check that your computer is finding the shared libraries with the following:

josh@yoga:~$ ldconfig -p | grep local
	libsvn_ra_local-1.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libsvn_ra_local-1.so.1
	libsphinxbase.so.3 (libc6,x86-64) => /usr/local/lib/libsphinxbase.so.3
	libsphinxbase.so (libc6,x86-64) => /usr/local/lib/libsphinxbase.so

Now you should be able to run the sphinxbase executables, and get a more reasonable error:

josh@yoga:~$ sphinx_lm_convert
ERROR: "cmd_ln.c", line 679: No arguments given, available options are:
Arguments list definition:
[NAME]		[DEFLT]	[DESCR]
-case			Ether 'lower' or 'upper' - case fold to lower/upper case (NOT UNICODE AWARE)
-debug			Verbosity level for debugging messages
-help		no	Shows the usage of the tool
-i			Input language model file (required)
-ifmt			Input language model format (will guess if not specified)
-lm_trie	no	Whether trie structure should be used for model holding during convertion
-logbase	1.0001	Base in which all log-likelihoods calculated
-mmap		no	Use memory-mapped I/O for reading binary LM files
-o			Output language model file (required)
-ofmt			Output language model file (will guess if not specified)

Installing pocketsphinx

Now that we’ve got sphinxbase installed successfully, we can move onto installing pocketsphinx. According to the description on the pocketsphinx GitHub repository:

PocketSphinx is a lightweight speech recognition engine, specifically tuned for handheld and mobile devices, though it works equally well on the desktop.

Still using sphinx-source as our current working directory, we can clone pocketsphinx from GitHub with the following command:

josh@yoga:~/Desktop/sphinx-source$ git clone https://github.com/cmusphinx/pocketsphinx.git
Cloning into 'pocketsphinx'...
remote: Counting objects: 11810, done.
remote: Total 11810 (delta 0), reused 0 (delta 0), pack-reused 11810
Receiving objects: 100% (11810/11810), 178.73 MiB | 11.30 MiB/s, done.
Resolving deltas: 100% (8831/8831), done.
Checking connectivity... done.

If we peek inside the current working directory, we will see we have a new directory:

josh@yoga:~/Desktop/sphinx-source$ la
pocketsphinx  sphinxbase

Now lets take a look at all the stuff we’ve just cloned:

josh@yoga:~/Desktop/sphinx-source$ la pocketsphinx
AUTHORS       doc      indent.sh  Makefile.am  pocketsphinx.pc.in  README.md   swig
autogen.sh    .git     LICENSE    model        pocketsphinx.sln    regression  test
configure.ac  include  m4         NEWS         README              src         win32

Looks pretty similar to what we found in our sphinxbase source directory, right?

It basically is, and we can run the same installation procedure as we did above. So now we cd into the dir itself and run autogen.sh. We get some output that looks like the following (again, I’ve truncated the output here).

josh@yoga:~/Desktop/sphinx-source$ cd pocketsphinx
josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ ./autogen.sh 
**Warning**: I am going to run `configure' with no arguments.
If you wish to pass any to it, please specify them on the
`./autogen.sh' command line.

processing .
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
Running aclocal  ...
Running automake --foreign --copy  ...
configure.ac:11: installing './compile'
configure.ac:10: installing './config.guess'
configure.ac:10: installing './config.sub'
configure.ac:5: installing './install-sh'
                    .
                    .
                    .
config.status: creating model/Makefile
config.status: creating test/Makefile
config.status: creating test/testfuncs.sh
config.status: creating test/unit/Makefile
config.status: creating test/regression/Makefile
config.status: executing depfiles commands
config.status: executing libtool commands
Now type `make' to compile the package.

Now we’ve made all our necessary Makefiles, and we can see them in the pocketsphinx directory.

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ la
aclocal.m4      configure     libtool      model               README.md
AUTHORS         configure.ac  LICENSE      NEWS                regression
autogen.sh      doc           m4           pocketsphinx.pc     src
autom4te.cache  .git          Makefile     pocketsphinx.pc.in  swig
config.log      include       Makefile.am  pocketsphinx.sln    test
config.status   indent.sh     Makefile.in  README              win32

Same as we did above for sphinxbase, we run make now.

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ make
                             .
                             .
                             .
libtool: link: (cd ".libs" && rm -f "_pocketsphinx.so.0" && ln -s "_pocketsphinx.so.0.0.0" "_pocketsphinx.so.0")
libtool: link: (cd ".libs" && rm -f "_pocketsphinx.so" && ln -s "_pocketsphinx.so.0.0.0" "_pocketsphinx.so")
libtool: link: ar cru .libs/_pocketsphinx.a  pocketsphinx_wrap.o
libtool: link: ranlib .libs/_pocketsphinx.a
libtool: link: ( cd ".libs" && rm -f "_pocketsphinx.la" && ln -s "../_pocketsphinx.la" "_pocketsphinx.la" )
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig/python'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig/python'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx'

And now we can actually do the installation with make install and root privledges.

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ sudo make install
Making install in src
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx/src'
Making install in libpocketsphinx
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx/src/libpocketsphinx'
make[3]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx/src/libpocketsphinx'
                             .
                             .
                             .
libtool: install: /usr/bin/install -c .libs/libpocketsphinx.lai /usr/local/lib/libpocketsphinx.la
libtool: install: /usr/bin/install -c .libs/libpocketsphinx.a /usr/local/lib/libpocketsphinx.a
libtool: install: chmod 644 /usr/local/lib/libpocketsphinx.a
libtool: install: ranlib /usr/local/lib/libpocketsphinx.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                             .
                             .
                             .
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib/python2.7/dist-packages/pocketsphinx

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                             .
                             .
                             .
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx'
make[2]: Nothing to be done for `install-exec-am'.
 /bin/mkdir -p '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 pocketsphinx.pc '/usr/local/lib/pkgconfig'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx'

Let’s see if we got something. If you type in pocketsphinx_ and do a tab completion to list all options, you should see something like this:

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ pocketsphinx_
pocketsphinx_batch         pocketsphinx_continuous    pocketsphinx_mdef_convert

Now if you try to run one of them, we get a sensible error that says we didn’t supply any of the needed arguments.

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ pocketsphinx_continuous 
ERROR: "cmd_ln.c", line 679: No arguments given, available options are:
Arguments list definition:
[NAME]			[DEFLT]		[DESCR]
-adcdev					Name of audio device to use for input.
-agc			none		Automatic gain control for c0 ('max', 'emax', 'noise', or 'none')
-agcthresh		2.0		Initial threshold for automatic gain control
-allphone				Perform phoneme decoding with phonetic lm
-allphone_ci		no		Perform phoneme decoding with phonetic lm and context-independent units only
-alpha			0.97		Preemphasis parameter
                              .
                              .
                              .
-varfloor		0.0001		Mixture gaussian variance floor (applied to data from -var file)
-varnorm		no		Variance normalize each utterance (only if CMN == current)
-verbose		no		Show input filenames
-warp_params				Parameters defining the warping function
-warp_type		inverse_linear	Warping function type (or shape)
-wbeam			7e-29		Beam width applied to word exits
-wip			0.65		Word insertion penalty
-wlen			0.025625	Hamming window length

INFO: continuous.c(295): Specify '-infile <file.wav>' to recognize from file or '-inmic yes' to recognize from microphone.

Huzzah! We now have a functional version of pocketsphinx installed with all it’s sphinxbase dependencies (if you followed the first section). If you already have a language model, an acoustic model, and a phonetic dictionary, you’re good to go!

However, if you’d like to train or adapt an acoustic model, you need to install sphinxtrain as shown below.

Installing sphinxtrain

Let’s clone sphinxtrain into the temporary directory we’ve been using to store our source code (sphinx-source):

josh@yoga:~/Desktop/sphinx-source$ git clone https://github.com/cmusphinx/sphinxtrain.git
Cloning into 'sphinxtrain'...
remote: Counting objects: 15997, done.
remote: Total 15997 (delta 0), reused 0 (delta 0), pack-reused 15997
Receiving objects: 100% (15997/15997), 13.15 MiB | 1.80 MiB/s, done.
Resolving deltas: 100% (11174/11174), done.
Checking connectivity... done.

If we look inside the temorary directory, we see sphinxtrain right where it should be, alongside our other directories of source code.

josh@yoga:~/Desktop/sphinx-source$ la
pocketsphinx  sphinxbase  sphinxtrain

Now, if we look inside this new sourcecode, we will see something pretty familiar.

josh@yoga:~/Desktop/sphinx-source$ la sphinxtrain
AUTHORS       etc      LICENSE      NEWS    scripts          templates
autogen.sh    .git     m4           python  SphinxTrain.sln  test
configure.ac  include  Makefile.am  README  src              win32

Let’s cd into sphinxtrain and run the script which generates the Makefiles.

josh@yoga:~/Desktop/sphinx-source$ cd sphinxtrain
josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ ./autogen.sh 
**Warning**: I am going to run `configure' with no arguments.
If you wish to pass any to it, please specify them on the
`./autogen.sh' command line.

processing .
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
                      .
                      .
                      .
config.status: creating src/programs/param_cnt/Makefile
config.status: creating src/programs/printp/Makefile
config.status: creating src/programs/prunetree/Makefile
config.status: creating src/programs/tiestate/Makefile
config.status: creating test/Makefile
config.status: executing depfiles commands
config.status: executing libtool commands
Now type `make' to compile the package.

Let’s take a look at what we just did.

josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ la
aclocal.m4      config.status  include     Makefile.am  SphinxTrain.sln
AUTHORS         config.sub     install-sh  Makefile.in  src
autogen.sh      configure      libtool     missing      templates
autom4te.cache  configure.ac   LICENSE     NEWS         test
compile         depcomp        ltmain.sh   python       win32
config.guess    etc            m4          README
config.log      .git           Makefile    scripts

As with all the other installations, we now compile with make.

josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ make
                            .
                            .
                            .
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src/programs/tiestate'
make[3]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src/programs'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src/programs'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src/programs'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
Making all in test
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain'

Moving right along, we can run make install to seal the deal.

josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ sudo make install
                            .
                            .
                            .
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[3]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
Making install in test
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain'

Hopefully now you can try out sphinxtrain and get some sensible output:

josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ sphinxtrain 

Sphinxtrain processes the audio files and creates and acoustic model 
for CMUSphinx toolkit. The data needs to have a certain layout 
See the tutorial http://cmusphinx.sourceforge.net/wiki/tutorialam 
for details

Usage: sphinxtrain [options] <command>

Commands:
     -t <task> setup - copy configuration into database
     [-s <stage1,stage2,stage3>] [-f <stage>] run - run the training or just selected stages

You should be ready to go now!

Hopefully this was helpful for you. If you ran into issues or have suggestions on how to make this better, be sure to leave a comment!

Installing cmuclmtk

I can’t seem to find the code on CMU-Sphinx’s GitHub account, so I’m just went through sourceforge instead.

NB A reader recommended to try this link from svn instead: svn://svn.code.sf.net/p/cmusphinx/code/trunk/cmuclmtk

josh@yoga:~/Desktop$ svn checkout svn://svn.code.sf.net/p/cmusphinx/code/trunk cmusphinx-code
                           .
                           .
                           .
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/wfreq2vocab.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/idngram2stats.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/text2wngram.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/lm_combine.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/interpolate.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/binlm2arpa.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/phoenix2corpus.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/text2idngram.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/ngram2mgram.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/text2wfreq.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/idngram2lm.exe
Checked out external at revision 10678.

Checked out revision 13167.

As you can see below, we just downloaded pretty much everything they’ve got. Importantly, cmuclmtk is there, too.

josh@yoga:~/Desktop$ cd cmusphinx-code/
josh@yoga:~/Desktop/cmusphinx-code$ la
cmuclmtk  htk2s3conv  multisphinx   pocketsphinx-android       sphinx2  sphinx4     sphinxtrain
cmudict   logios      pocketsphinx  pocketsphinx-android-demo  sphinx3  sphinxbase  .svn

Let’s cd into cmuclmtk and take a look:

josh@yoga:~/Desktop/cmusphinx-code$ cd cmuclmtk/
josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ la
AUTHORS     ChangeLog     configure.ac  doc      Makefile.am  perl    src   TODO
autogen.sh  cmuclmtk.sln  debian        LICENSE  NEWS         README  test  win32

Familiar set up, right? We do the same steps as before, starting with ./autogen.sh.

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ ./autogen.sh 
**Warning**: I am going to run `configure' with no arguments.
If you wish to pass any to it, please specify them on the
`./autogen.sh' command line.

processing .
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
              .
              .
              .
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating test/Makefile
config.status: creating src/liblmest/Makefile
config.status: creating src/libs/Makefile
config.status: creating src/programs/Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
Now type `make' to compile the package.

Here’s all the things we’ve just generated:

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ la
aclocal.m4      cmuclmtk.sln  config.log     debian      LICENSE      Makefile.in  src
AUTHORS         compile       config.status  depcomp     ltmain.sh    missing      stamp-h1
autogen.sh      config.guess  config.sub     doc         m4           NEWS         test
autom4te.cache  config.h      configure      install-sh  Makefile     perl         TODO
ChangeLog       config.h.in   configure.ac   libtool     Makefile.am  README       win32

Now we run make.

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ make
                       .
                       .
                       .
libtool: link: gcc -I../../src/libs -I../../src/liblmest -I../../src/win32 -g -O2 -o .libs/lm_combine lm_combine.o  ../../src/.libs/libcmuclmtk.so -lm
make[3]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/src/programs'
make[2]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/src'
Making all in test
make[2]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/test'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/test'
make[2]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[1]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'

And finally, sudo make install.

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ sudo make install
[sudo] password for josh: 
Making install in src
make[1]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/src'
                              .
                              .
                              .
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                              .
                              .
                              .
make[1]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/test'
make[1]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[2]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[1]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'

Now we can see a couple of the executables if we do a tab completion as such:

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ text2
text2idngram  text2wfreq    text2wngram   

And if we run one without input, it hangs up and runs for a while, but works.

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ text2wfreq 
text2wfreq : Reading text from standard input...

Source: http://jrmeyer.github.io/installation/2016/01/09/Installing-CMU-Sphinx-on-Ubuntu.html

Selenium Grid Step by Step Guide


Install java jar:

1. Add the PPA.

Open terminal (Ctrl+Alt+T) and run the command:

sudo add-apt-repository ppa:webupd8team/java

Type in your password when it asks and hit Enter.

2. Update and install the installer script:

Run commands to update system package index and install Java installer script:

sudo apt update; sudo apt install oracle-java8-installer

You may replace oracle-java8-installer with oracle-java9-installer to install Java 9.

While the install process, you have to accept Java license to continue downloading & installing Java binaries.

3. Check the Java version

To check the Java version after installing the package, run command:

javac -version

4. Set Java environment variables

The PPA also contains a package to automatically set Java environment variables, just run command:

sudo apt install oracle-java8-set-default

For Java 9, install the package oracle-java9-set-default instead.

Setup Selenium Standalone Server

 1. Download Selenium Selenium Standalone Server:

Go to http://www.seleniumhq.org/download/ and then download Selenium Standalone Server by clicking ‘Download version 3.0.1‘ (version number may vary).

You need to download this for both hub and node PCs

2. Now, start the Hub machine:

Open the terminal, CD to the location where the selenium standalone server file is being kept and type:

java -jar selenium-server-standalone-2.30.0.jar -role hub

It will start the hub.

Another way to verify whether the hub is running is by using a browser. Selenium Grid, by default, uses hub’s port 4444 for its web interface. Simply open up a browser and go to http://localhost:4444/grid/console

Also, you can find if the node can access the hub. For this, open a browser in the node machine and type http://192.168.136.130:4444/grid/console as URL. Here ‘192.168.136.130’ should replace with the node machine’s IP address.

3. Now, the hub is up and running. Let’s setup node:

In the node machine, open a terminal, CD to the location where the selenium standalone jar file is located and type the following command:

java -jar selenium-server-standalone-3.0.1.jar -role webdriver -hub http://192.168.136.130:4444/grid/register -port 5566

Here, 192.168.136.130 should be replaced with the hub machine’s IP address.

We also used port 5566 though you may choose any free port number you desire.

If everything went well, the node will up and show it’s status.

You can also verify if the node is connected with hub properly from the web browser.

Refresh the http://192.168.136.130:4444/grid/console URL and it will show the connected nodes.

4. Run the selenium script:

Now, we will run a selenium remote control script from the hub machine and it will execute to the node machines.

Here is a sample python script we are using:

Please Note: To run this script the node pc must have installed the following things:

  1. Python
  2. Python PIP
  3. Selenium
  4. Latest Chrome driver

Remote Control Script:

# -*- coding: utf-8 -*-
from selenium import selenium
import unittest, time, re

class sample-script(unittest.TestCase):
 def setUp(self):
 self.verificationErrors = []
 self.selenium = selenium("localhost", 4444, "*chrome", "http://jaxara.com/")
 self.selenium.start()
 
 def test_sample-script(self):
 sel = self.selenium
 sel.open("/")
 sel.type("id=edit-search-block-form--4", "test")
 sel.click("xpath=.//*[@value='Search']")
 for i in range(60):
 try:
 if sel.is_element_present("xpath=.//*[@id='block-system-main']/div/h2"): break
 except: pass
 time.sleep(1)
 else: self.fail("time out")
 try: self.failUnless(sel.is_element_present("xpath=.//*[@id='block-system-main']/div/h2"))
 except AssertionError as e: self.verificationErrors.append(str(e))
 
 def tearDown(self):
 self.selenium.stop()
 self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
 unittest.main()

To verify if the above listed items are already been installed, run this script from the terminal. If the following scripts run properly then everything is installed and ready.

Sample Script:

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class SampleWebScriptPy(unittest.TestCase):
 def setUp(self):
 self.driver = webdriver.Chrome()
 self.driver.implicitly_wait(30)
 self.base_url = "http://jaxara.com/"
 self.verificationErrors = []
 self.accept_next_alert = True
 
 def test_sample_web_script_py(self):
 driver = self.driver
 driver.get(self.base_url + "/")
 driver.find_element_by_id("edit-search-block-form--4").clear()
 driver.find_element_by_id("edit-search-block-form--4").send_keys("test")
 driver.find_element_by_xpath(".//*[@value='Search']").click()
 for i in range(60):
 try:
 if self.is_element_present(By.XPATH, ".//*[@id='block-system-main']/div/h2"): break
 except: pass
 time.sleep(1)
 else: self.fail("time out")
 try: self.assertTrue(self.is_element_present(By.XPATH, ".//*[@id='block-system-main']/div/h2"))
 except AssertionError as e: self.verificationErrors.append(str(e))
 
 def is_element_present(self, how, what):
 try: self.driver.find_element(by=how, value=what)
 except NoSuchElementException as e: return False
 return True
 
 def is_alert_present(self):
 try: self.driver.switch_to_alert()
 except NoAlertPresentException as e: return False
 return True
 
 def close_alert_and_get_its_text(self):
 try:
 alert = self.driver.switch_to_alert()
 alert_text = alert.text
 if self.accept_next_alert:
 alert.accept()
 else:
 alert.dismiss()
 return alert_text
 finally: self.accept_next_alert = True
 
 def tearDown(self):
 self.driver.quit()
 self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
 unittest.main()

Good luck!

Create a free website or blog at WordPress.com.

Up ↑