Skip to main content

Posts

Showing posts with the label selenium

Docker Compose a Selenium Grid

There are times when you would like to Selenium Grid quickly so that it can scale to whatever testing goal is you want to achieve. To start out you will need to get Docker you can goto Docker.com to find out more information on installing. Create a docker-compose.yml Make a new directory and name a file docker-compose.yml inside that directory. The contents are below. hub: image: selenium/hub ports: - "4444:4444" chrome: image: selenium/node-chrome links: - hub expose: - "5555" firefox: image: selenium/node-firefox links: - hub expose: - "5555" Once you have created your file goto that directory in your command line. This will create your instances and download necessary files. $ docker-compose build To run your instances you can run the following and it will start your servers. $ docker-compose up At this point you can now point your test code to http://127.0.0.1:4444 as the selenium server. You will n...

Scrolling to place on webpage for Protractor or Webdriver testing.

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) +');')) }); }