Harrington Web

Scrolling to place on webpage for Protractor or Webdriver testing.

Monday, October 26, 2015
Sometimes when using a Selenium by product like Protractor for testing Angular applications, I run into issues trying to access certain elements. In some cases it is because our UI folks may have another element that hovers over an area rather than actually take up that space. In cases like these I need to move the content on the page similar to how a user would so that the content I need is the front most element on the page. To do this I made a simple scrollTo function that will take a Selenium element and tell the browser with executeScript to goto those coordinates. I also have an offset so that I can move it around the would be elements that cover my element.

function scrollToElement(element, offset) {
  offset = offset || 0;
  element.getLocation()
    .then( function(loc) {
      browser.executeScript(('window.scrollTo('+loc.x+','+ (loc.y - offset) +');'))
    });
}

Add big numbers in Javascript as strings.

Tuesday, September 8, 2015
function pad(a, b) {
  for (var i = 0; i < b.length - a.length; i++) {
    a = "0" + a;
  }
  return a;
}

function stringAdd(a, b) {
  var total = "";
  var carry = 0;
  a = pad(a, b);
  b = pad(b, a);
  for (var i = b.length - 1; i >= 0; i = i - 1) {
    var x = (parseInt(a[i]) + parseInt(b[i]) + carry);
    carry = 0;
    if (x >= 10) {
      carry = 1;
      x = x - 10;
    }
    total = x.toString() + total;
  }
  if (carry == 1) {
    total = "1" + total;
  }
  return total;
}

Docker - Remove All

Wednesday, August 19, 2015
Sometimes you just need to remove everything from Docker and have a clean slate.

# Delete all containers
docker rm $(docker ps -a -q)

# Delete all images
docker rmi $(docker images -q)