Labor has retained government in Western Australia, with Roger Cook leading his party to a historic third consecutive election win.