I'm looking for someone to tell me how can I avoid to re-enter everytime the username and password when I run a Testdrive with webdriverIO using the chromedriver and selenium. What I want is to optimize my testdrive. Some clue???
this two file are parts of one module and there is 4 modules in the system
first file:
var name = 'Andrea' + Math.floor((Math.random() * 1000000) + 1);
var ssn = 'V-' + Math.floor((Math.random() * 1000000) + 1);
var url = 'http://someurl.com';
var new_contact = 'https://someurl.com/client/add';
describe('Some contact is create', function(){
it('Should login to the system', function(){
browser.url(url)
browser.setValue('#email','xxxxxxxx@xxxx.com')
browser.setValue('#password','xxxxxx')
browser.click('#submit');
});
it('Should be fill the form', function(){
browser.url(new_contact)
browser.waitForVisible('#addClient')
browser.setValue('#clientNameTextField-inputEl',name)
browser.setValue('#clientIdentidicationTextField-inputEl',ssn)
browser.setValue('#clientAddressTextField-inputEl','El busque')
browser.setValue('#clientCicyyTextField-inputEl','Valencia')
browser.setValue('#clientEmailField-inputEl','salvador.salvatierra@alegra.com')
browser.setValue('#clientPhoneTextField-inputEl','04141234567')
browser.setValue('[name="phone2"]','04147654321')
});
it('the contact is store',function(){
browser.click('=save)
browser.waitForExist('#viewClientInfoBalances')
browser.end;
});
});
second file:
var url = 'http://someurl.com';
describe('We get the basic info from index contact', function(){
it('Shouldlogin to the system', function(){
browser.url(url)
browser.setValue('#email','xxxxxxxx@xxx.com')
browser.setValue('#password','xxxxx')
browser.click('#submit');
});
it('We should see the basic info', function(){
browser.click('[href="/client"]')
browser.click('#gridview-1043-record-ext-record-66 .action-icons a:nth-child(1)')
browser.waitForExist('#viewClientInfoBalances')
browser.end();
});
});
I see three possible solutions of different approaches:
Since I see you're using Mocha, then I would go for running your login snippet before all your test-cases in a
.before()
hook:Obs: The
.before()
hook will be run ONLY ONCE, per test-suite. If you have different test-suites (describe
statements) in which you need a login for every test-case, then use the.beforeEach()
hook.Update !!! As per Salvador's requirement, in the comment section, this part has been added.
You have two ways to achieve this:
Move your Login in the
wdio.config.js
beforeSuite
hook:Create a
main.js
file where you inject all your "modules". You login from that file alone and inject all yourdescribe
-populated files viarequire
in it:Injector:
main.js:
browser.debug()
after you load your page;C:\Users\<yourUserName>\Desktop\scoped_dir18256_17319\Default
, copy the scoped_dir18256_17319 folder on your Desktop). This folder contains all the actions (search history, extensions installed, accounts saved/saved credentials in our case) on THIS current instance;Now all we need to do, is add the path to that folder in your
wdio.config.js
file as achromeOptions
argument:Now all you have to do is run your test cases with this custom profile and you will be logged in with your preferred username/password combination.
Obs: You can read more about Custom Profiles HERE, Use Custom Profile section.
cookies
);.cookie()
, or.setCookie()
methods.Code should look like this:
See THIS answer I gave to a similar question as an example.
Hope this helps you. Cheers!