Skip to content

Instantly share code, notes, and snippets.

View jaffamonkey's full-sized avatar
🏠
Working from home

Paul Littlebury jaffamonkey

🏠
Working from home
View GitHub Profile
<!-- image -->
// An example of running Pa11y programmatically
'use strict';
var pa11y = require('pa11y');
var url = 'http://localhost/search';
// Create a test instance with some default options
var test = pa11y({
parameters: {
this.Given(/^I click the (.*) (button|filter|radio|tab|checkbox|link|icon|record|person|asset|accordion)$/,
function (elementId, callback)
{ var elm = element(by.css('#' + elementId));
var EC = protractor.ExpectedConditions;
var isClickable = EC.elementToBeClickable(elm);
browser.wait(isClickable, 20000);
elm.click().then(callback);
});
@jaffamonkey
jaffamonkey / downloadInstallRunJMeter.sh
Last active February 3, 2018 13:16
CLI: Download, install and run JMeter
#!/bin/bash
# Download and install JMeter
wget http://mirror.reverse.net/pub/apache//jmeter/binaries/apache-jmeter-3.3.tgz && wget https://www.apache.org/dist/jmeter/binaries/apache-jmeter-3.3.tgz.asc && wget -O - https://www.apache.org/dist/jmeter/KEYS |gpg --import && gpg --verify apache-jmeter-3.3.tgz.asc && tar -zxf apache-jmeter-3.3.tgz && rm apache-jmeter-3.3.tgz
# Run load test and create dashboard with stats and graphs
./apache-jmeter-3.3/bin/jmeter -n -t load-test-plan.jmx -l ../reports/html/jmeterreport2.jtl -e -o /dashboard"
@jaffamonkey
jaffamonkey / XMLparsingwithPHP.php
Created February 3, 2018 13:09
XML parsing with PHP (using file_get_contents and SimpleXmlElement)
$context = stream_context_create( array( 'http' => array( 'follow_location' => false ) ) );
$content = file_get_contents("http://xyogasangeetax.api.channel.livestream.com/2.0/latestclips.xml", false, $context);
$data = new SimpleXmlElement($content);
foreach($data->channel->item as $entry)
{ if ($media = $entry->children('media', TRUE))
{ echo "<div style=\"width:160px;display:block;float:left;padding:15px;\">";
$attributes = $media->content->attributes();
$src = $play_attributes['url'];
if ($media->thumbnail)
{ $attributes = $media->thumbnail->attributes();
@jaffamonkey
jaffamonkey / webdriverio-search-results.js
Created February 3, 2018 13:12
webdriverio example of a search followed by a check on each search result row.
browser.setValue('#search-keywords', 'test');
browser.click('#search-button');
const links = $$('#search-result-row');
links.forEach(function (link) {
let elem = link.getText();
expect(elem).to.contain('test');
});
@jaffamonkey
jaffamonkey / TravisMatrix.yml
Created February 3, 2018 13:15
TravisCI Matrix enables you to run two or more jobs concurrently. For example, it is prudent to separate out load tests and UI tests. The following travis.yml extract illustrates this.
env:
matrix:
- TESTTYPE=cucumber
- TESTTYPE=jmeter
- if [[ "$TESTTYPE" == "cucumber" ]]; then docker exec -ti par_beta_web bash -c "cd tests && /usr/local/n/versions/node/7.2.1/bin/npm run test:build"; fi


- if [[ "$TESTTYPE" == "jmeter" ]]; then docker exec -ti par_beta_web bash -c "cd tests/jmeter && ./apache-jmeter-3.3/bin/jmeter -n -t load-test-plan-travis.jmx -l ../reports/jmeterreport.jtl -e -o ../reports/dashboard"; fi
@jaffamonkey
jaffamonkey / ClickJackingCSSprotection.html
Last active February 3, 2018 13:20
Adding click-jacking and cross-site scripting protection to header
X-Content-Type-Options nosniff;
X-XSS-Protection "1; mode=block";
X-Frame-Options "SAMEORIGIN" always;
@jaffamonkey
jaffamonkey / CucumberJSSwitchStep.js
Created February 3, 2018 13:25
'Switch' checks for a certain value, then ascribes variables with certain values based on result.
this.Given(/^I should see quantity (.*) for product (.*) on the (.*) page$/, function(quantity, productid, sitepage, callback) {
var url, i;
switch (sitepage) {
case 'hardware section':
url = 'http://ashop.com/category/hardware-section/';
i = 11;
break;
case 'product page':
url = 'http://ashop.com/category/hardware-section/product/1234/';
i = 9;
@jaffamonkey
jaffamonkey / CucumberJSProtractorDropdown.js
Last active February 3, 2018 13:29
Commonly dropdowns that can be overly long, and implement an "as-you-type" filter. This is one way to test this (using CucumberJS/Protractor)
this.Given(/^I select (.*) from (.*)$/, function(selection, dropdown) {
// click on dropdown field to initiate dropdown element(by.css('.dropdown')).click().then(function ()
{
var dropdownField = element(by.id(dropdown));
//clear the as-you-type field if already populated
dropdownField.clear().then(function() {
// enter text to search dropdown values
sendKeys(dropdownField, selection);
// click TAB button to exit (populated) field
return dropdownField.sendKeys(protractor.Key.TAB);
@jaffamonkey
jaffamonkey / .travis.yml
Created May 3, 2018 12:49
Travis file for running Nightwatch/CucumberJS tests on iOS using Appium/XCode
sudo: required
os: osx
language: node_js
node_js: '7'
include:
- osx_image: xcode9.2
env: DEVICE=10.2
before_script: