The call driver.get(url)causes errors when I try to link it with other functions. Here are my little functional methods:
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
const R = require('ramda');
const loadPage = url => driver => driver.get(url)
const getElement = locator => driver => driver.findElement(method)
const byName = name => By.name(name)
const sendKeys = keys => elem => elem.sendKeys(keys)
The following minimal example loads Google and writes a message to the search bar. It works:
const loadGoogle = loadPage('http://google.com')
const getSearchForm = getElement(byName('q'))
const driver = new webdriver.Builder().forBrowser('chrome').build();
loadGoogle(driver);
var app = R.compose(sendKeys('search input'), getSearchForm)
app(driver);
But I want to include loadGooglein the composition of the function - it will be more accurate and more "correct". For instance:
var app = R.compose(sendKeys('search input'), getSearchForm, loadGoogle)
app(driver);
But I get the error driver.findElement is not a function:
/Users/name/Desktop/functional-test.js:9
const getElement = locator => driver => driver.findElement(locator)
^
TypeError: driver.findElement is not a function
at driver (/Users/name/Desktop/functional-test.js:9:48)
at /Users/name/node_modules/ramda/src/internal/_pipe.js:3:14
at /Users/name/node_modules/ramda/src/internal/_pipe.js:3:27
at /Users/name/node_modules/ramda/src/internal/_arity.js:5:45
at Object.<anonymous> (/Users/name/Desktop/functional-test.js:28:1)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
I suppose because it loadPagedoes not return an instance of WebDriver , but I am not sure and do not know how to fix it.
source
share