• Automated testing with Drupal 8 + Selenium + Behat + Gherkins + Jenkins + Cucumber

    Here's a simple guide on how to setup automated testing with Behat, Behat Gherkins, Selenium, Jenkins and Cucumber with Drupal 8/9. In this guide, we will be using a Drupal 8 instance with composer. Setup Behat for Drupal 8/9 First thing we need to do is to install all the composer libraries that we need by installing drupal/drupal-extension. composer require drupal/drupal-extension --dev Creating a file called behat.yml inside the root directory of your project  default: suites: default: contexts: - FeatureContext - Drupal\DrupalExtension\Context\DrupalContext - Drupal\DrupalExtension\Context\MinkContext extensions: Behat\MinkExtension: goutte: ~ base_url: javascript_session: selenium2 browser_name: 'chrome' selenium2: wd_host: http://localhost:4444/wd/hub capabilities: { "browser": "chrome", "version": "*", 'chrome': {'switches':['--start-maximized']}} Drupal\DrupalExtension: blackbox: ~ api_driver: drupal drupal: drupal_root: web/ region_map: navigation: ".navbar-header" navigation_collapsible: "#navbar-collapse" header: ".region-header" highlighted: ".highlighted" help: ".region-help" content: ".main-content" sidebar_first: ".region-sidebar-first" sidebar_second: ".region-sidebar-second" footer: ".footer" local: extensions: Drupal\MinkExtension: base_url: http://mysite.localhost:8000 Initialize behat. This creates the features folder where we will put all our features files and some of our custom context if we needed. Custom context will be inside the features/bootstrap directory. behat --init +d features/bootstrap - place your context classes here +f features/bootstrap/FeatureContext.php - place your definitions, transformations and hooks here To check if everything is working as expected, you can try listing definitions by: behat -dl You should see something like this: default | Given I am an anonymous user default | Given I am not logged in default | Then I log out default | Given I am logged in as a user with the :role role(s) default | Given I am logged in as a/an :role default | Given I am logged in as a user with the :role role(s) and I have the following fields: default | Given I am logged in as :name default | Given I am logged in as a user with the :permissions permission(s) default | Then I should see (the text ):text in the :rowText row default | Then I should not see (the text ):text in the :rowText row default | Given I click :link in the :rowText row default | Then I (should )see the :link in the :rowText row default | Given the cache has been cleared default | Given I run cron ...   Setup Selenium server with Chrome driver On this part, we will be using a standalone Selenium server. Create a directory that you can easily access. E.g.: mkdir ~/selenium-server Download the standalone Selenium server  and move it in to the folder you just created. Download your desired browser to use for testing. In this guide, we will be using Chrome driver. Head to to download the right Chrome driver version that fits your Chrome browser version.  Extract the zip file and move the chromedriver executable file in to the same folder we created. Run the server cd ~/selenium-server java -jar selenium-server-standalone-3.141.59.jar     Create feature and run the test Create a new file inside features folder and name it like homepage.feature @api @javascript Feature: Homepage check Scenario: Anonymous user access Given I am an anonymous user When I visit "/" Then I should see the text "Featured" in the "content" region This example feature file will access the homepage as an anonymous user and will look for the text "Featured" in the "content" region (which the css selector were specified in the behat.yml)   Now let's run the test by executing: behat --profile local I'm running the local profile (which we also specified the url from our behat.yml) since I'm running the test from my local.  
  • Jenkins

    Jenkins (standalone) SSL + Let's Encrypt

    In this tutorial, I will show how to use Let's Encrypt free SSL with a standalone Jenkins in Ubuntu 16.04.   Installation of certbot and jenkins are not included in this tutorial.   Generate Certificates Run the command to generate the certificate and key files. sudo certbot certonly --standalone --preferred-challenges http -d You should get this response: Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator standalone, Installer None Obtaining a new certificate Performing the following challenges: http-01 challenge for Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/ Your key file has been saved at: /etc/letsencrypt/live/ Your cert will expire on 2019-02-07. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: Donating to EFF: Just in case you got this response: Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator standalone, Installer None Obtaining a new certificate Performing the following challenges: http-01 challenge for Cleaning up challenges Problem binding to port 80: Could not bind to IPv4 or IPv6. You need to stop your web server and try again.   Convert the certificate to JKS keystore Go to your certificate folder cd /etc/letsencrypt/live/ And execute this command to convert the certificate to PKCS12 file first openssl pkcs12 -inkey privkey.pem -in fullchain.pem -export -out keys.pkcs12 If you are renewing the certificates, make sure to delete the existing /var/lib/jenkins/jenkins.jks file first. Then convert to JKS file keytool -importkeystore -srckeystore keys.pkcs12 -srcstoretype pkcs12 -destkeystore /var/lib/jenkins/jenkins.jks Enter export and import passwords and answer "yes" if asked to overwrite an existing alias Enter Export Password: Verifying - Enter Export Password: root@example:/etc/letsencrypt/live/ keytool -importkeystore -srckeystore keys.pkcs12 -srcstoretype pkcs12 -destkeystore /var/lib/jenkins/jenkins.jks Importing keystore keys.pkcs12 to /var/lib/jenkins/jenkins.jks... Enter destination keystore password: Enter source keystore password: Existing entry alias 1 exists, overwrite? [no]: yes Entry for alias 1 successfully imported. Import command completed: 1 entries successfully imported, 0 entries failed or cancelled   Set Jenkins configuration to use the SSL Edit the Jenkins config file vim /etc/default/jenkins Look for JENKINS_ARGS and update the value to this: JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=-1 --httpsPort=8443 --httpsKeyStore=/var/lib/jenkins/jenkins.jks --httpsKeyStorePassword=PASSWORD_SET_ON_CONVERT_TO_JKS" Restart jenkins sudo service jenkins restart  
  • jenkins + bitbucket

    Setting up Jenkins item + Bitbucket

    In this article, I will share with you how I setup my Jenkins to get updates from Bitbucket. Jenkins Make sure you already installed Jenkins "Bitbucket Plugin" General This is where you put all the basic setting for your Jenkins item like Name, Description Source Code Management This is the part where you put your Bitbucket repository details. Put your repository URL in Repository URL input box. Credentials - The credentials for the repository URL. This should be your Bitbucket account credentials. Click the "Add" button beside the select box to create a new credential. Branch Specifier - The git branch you want to deploy. Usually you want to use "refs/heads/master" for the master branch. Build Triggers Tick "Build when a change is pushed to BitBucket" Build Click "Add build step" and select "Execute shell" and put all the shell commands you want to execute during build like running composer update and drush commands. Execute the build Server Login to SSH Create a symbolic link of your workspace We need to create the symbolic link of your project workspace to the actual project that was setup in your web server like Apache. ln -sv /var/lib/jenkins/workspace/[your-cool-project] /var/www/html/[your-cool-project]   Follow these steps to install Jenkins on Ubuntu 16.04