mardi 24 janvier 2017

Protractor testing for an selected option

I am writing tests with Protractor and Jasmine for an Angular v1 project.

I have to find a way to test if an option for a certain user role is selected.

HTML:

<select ng-model="user.groups" class="form-control" multiple ng-options="role for role in groups">
</select>

For my test, I know that the user needs to have a certain role and I need now confirm, that this one is selected.

What I have so far:

test-spec.js

it('should have the "admin" role checked', function () {
   teamSettingsModul.checkUserRole(userData.adminUser, 'admin');
});

team-settings-modul.js

exports.checkUserRole = function(user, role) {
     teamSettingsPage.openEditTeamMember(user);
     teamSettingsPage.roleSelected(role);
};

team-settings-page.js

this.roleSelected = function(roleName) {
    let select = element(by.model('user.groups')),
        option = select.$('[value=string:"'+roleName+'"]');
    expect(option.getText()).toBe(roleName);
    expect(option.getAttribute('selected')).toBe('selected');
}

Of course the last expect does not work and I get this back when running the test

Source - Team Settings Page Edit Form should have the "admin" role checked
Message:
Failed: invalid selector: An invalid or illegal selector was specified
  (Session info: chrome=55.0.2883.95)
  (Driver info: chromedriver=2.26.436421 (6c1a3ab469ad86fd49c8d97ede4a6b96a49ca5f6),platform=Mac OS X 10.11.6 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 16 milliseconds
For documentation on this error, please visit: http://ift.tt/1F7UoFL
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'Danielas-MacBook-Pro.local', ip: 'myIP', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_112'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.26.436421 (6c1a3ab469ad86fd49c8d97ede4a6b96a49ca5f6), userDataDir=/var/folders/8r/pllnd7_n0wd4nqptkmn3z3rm0000gn/T/.org.chromium.Chromium.G8gHx8}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.95, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: b03dc6b33eb855957c674a6dc3024033
*** Element info: {Using=css selector, value=[value=string:"admin"]}

Is there a way to test it? I have the feeling I am missing something here.

Aucun commentaire:

Enregistrer un commentaire