Thursday 17 August 2017

Selenium Tips - Node JS

So I've recently started making a few web user interface tests that can't be manually achieved with API calls. I was looking forward to practising my Node JS so thought I'd make it using that framework.

Here's a few little functions and commands to both get you going or help me remember what I've done:

Firstly, Selenium is a web browser automation software that can be run on the browser, in an application such as node or as an IDE. find out more HERE

Secondly, Node JS my desired programming service of the day is an open source platform built on a javascript runtime. There's a great youtube introductory video HERE

So... Getting Started. So I had installed node and created a dedicated directory.
I navigated to my new directory and installed selenium-webdriver:
 npm install selenium-webdriver
I then created an application:
echo "" > myNewApp.js
In the application I referenced selenium-webdriver and then used selenium builder to create a new browser driver like so:
const selenium = require('selenium-webdriver'),
    By = selenium.By,
    until = selenium.until;

var driver = new selenium.Builder()
    .forBrowser('chrome')
    .build();

var driver = new selenium.Builder()
    .forBrowser(‘firefox’)
    .build();
You'll either want different variable names for your different browsers or to only call one at a time!
From here on there are a whole bunch of commands we can run using driver.Command you can see a  list of some of the commands HERE.

The next thing to do is to perform a GET function on the webpage you want to navigate to in your automated test.
driver.get('www.myUrl.com').then(function(){
   console.log('Navigating to my page');

});
From this page we can perform a whole bunch of commands:
Populate an object:
driver.findElement(By.name(‘red’)).sendKeys(‘ABC’);
Clear a populated object:
driver.findElement(By.name(‘red’)).clear();
Make a hidden object visible:
driver.executeScript("document.getElementsByName(‘red’)[0].setAttribute('type', 'text');");
Using the drivers .then function will let you wait for something to occur and then perform the next action, such as wait for 2 seconds:
.then(function(){
  driver.sleep(2000);
});
You might want to click a button, all you need to know is the button class name. One way of doing this is to "inspect" the webpage from the browser.
Click:
driver.findElement(By.className('btn btn-lg')).click(); 
To quit the browser:
driver.quit(); 
The one thing I wasn't able to do was make a webpage stop loading to allow me to process a page that didn't stop. Let me know if you've done this before! I'd love to hear how you did it. 

Saturday 5 August 2017

A Beginners Guide to the Allotment

Louise and I have had the allotment for just over a year now and I thought it would be a good idea to get some thoughts down on our "Lessons Learnt" and some general advice for starting your own allotment.

Getting Started:
  1. Wait times for allotments can be very long! Up to 6 months in some councils as allotments need to be vacated before they can be reallocated.
  2. Allotments are measured in rods where 1 rod is around 5 meters
  3. Cost varies from council to council
  4. The first few tools you'll need are some pots, a spade, a fork and a watering can
  5. You will need a compost bin, pick an out of the way location that is relatively flat
  6. Start small, no need to dig the whole thing over at once.
  7. Ask neighbours for advice, most will be happy to help
  8. You can buy old tools very cheap at weekend markets, and local allotment organisations often sell seeds and compost, your local farmer will sell horse manure very cheap too
The What's What:
Some things look weird can you may find yourself wondering what other people are doing and why they have done them:
  1. Raised Beds - These are wooden borders around a small patch of land, they make it harder for slugs to eat your seeds.
  2. Fire Pits - Not all allotments allow them, and some only allow them between certain times. But here you can burn your weeds (like bind weed). The ash also makes great fertiliser!
  3. Fruit Cages - These keep the birds off the berries and trees
  4. Nets -  There will be nets and tunnels over seedlings, again to stop the birds. Some nets are specially designed to keep off frost, snow and bugs but still allow rain and sunlight.
  5. Tarp - This is usually put over a particularly weedy patch of land, it blocks out sunlight and kills the weeds at the roots. Normally left over the year ready for the new year.
Chemical Romance:
Here's some of the do and do nots around chemicals
  1. Slug Killer - in small doses keeps slugs at bay. However, pellets stay inside the slugs and the poison can have adverse affects on hedgehogs who can die from poisoning as well. There is also the case whereby if slug levels become too low there will be less millipedes, frogs and hedgehogs on your allotment meaning future slug populations will thrive without natural predators! Alternatives include; slug traps, putting them in the compost bin, raised beds, salt walls around plants.
  2. Weed Killer - I'm not adverse to weed killer itself but in the wind it can blow to other allotments killing other peoples vegetables. This is a big no no for obvious reasons. 
  3. Bug Killer - There are lots of home made formulas for killing white fly and aphids but some store bought products work just well.
Lessons Learnt:
We've all made mistakes in our lives, here are some of ours:
  1. Make sure you know what fruit/veg is what! We've pulled out strawberries we thought were weeds and grown raspberry bushes we thought was cauliflower. There's lots of apps for knowing what is what and books too!
  2. Plan what you will grow and when. Veg needs to be seeding pretty early in the year and inside your house is a perfect place whilst you get the allotment ready. Plants grow better in the greenhouse but the house can be good.
  3. Find a friend to agree to water your allotment whenever you're away. Alternatively fellow allotmenteers will sometimes offer, hence why we don't spray our neighbours allotments with weed killer! This is mainly important at the seed stage, less so when they're out in the wild.
  4. If you can't find someone, then there's ways of watering your seeds without human intervention. I've mentioned these before here: and we personally settled for this.
  5. Be careful when digging grassy bits of land, creatures great and small live there. Mice, frogs, hedgehogs etc. Killing a frog by accident is the worst! :(
  6. Composting can be a bit of an art. There's green and brown types of waste that can go in. Green is veg, leftover food and some weeds. Browns are dry leaves, cardboard from your house, tea bags and coffee grounds. The eden project do a good introduction here and a comprehensive video guide here.
That's all I have time for in this sitting! But I'll no doubt be back with a Part 2!

Do you have your own tips for new allotment holders? Are you having any particular problems on your own allotment? 

Leave a comment below to get in touch :)