PDA

View Full Version : Page Object value change



gmigliorini
24 Oct 2017, 9:07 AM
How would you go about testing a PageObject Text Field after changing its value?

If the value of the TextField is 'a' on load, then changed to 'b', stpo.PageObject.TextField.expect('value').toBe('b'); actually expects a still.

Is there any way to test that its value has changed?

daniel.gallo
24 Oct 2017, 6:09 PM
The example below demonstrates a couple of ways you can check a value has changed. I tested this against the Login (http://examples.sencha.com/extjs/6.5.1/examples/kitchensink/?classic#form-login) example in the Ext JS Kitchen Sink:


describe('Login screen', function() {
it('Should update login name correctly', function() {
// Check login field value is empty - use the built in "value" API, or a manual expectation
stpo.Login.login().value('');
stpo.Login.login().expect('value').toEqual('');

// Update login value
stpo.Login.login().setValue('dan');

// Check value has updated successfully - use the built in "value" API, or a manual expectation
stpo.Login.login().value('dan');
stpo.Login.login().expect('value').toEqual('dan');
});
});



And here is the associated page object:


ST.pageobject.define('Login', {
_locators: {
/**
* @method login
* @member stpo.Login
* @return {ST.future.TextField}
*/login: {
locator: 'textfield[name="user"]',
name: 'login',
type: 'textField',
className: 'ST.future.TextField'
}
}
});

gmigliorini
25 Oct 2017, 5:45 AM
Thank you for the reply Daniel.

While I understand this functionality my issue was testing the value property after doing things in the application instead of hard coding the setValue in Sencha test. I should have been more detailed in my question.

When setting the new field there is additional functionality where you are prompted a panel and this value is what I am not getting. In dev tools it is updating the value, but sencha test studio does see the new value.

daniel.gallo
26 Oct 2017, 3:46 PM
I'm unable to replicate this issue - are you sure Sencha Test is referencing the correct field in your application, which is why the value is not coming back?

Here's another example, which works against the Binding demo (http://examples.sencha.com/extjs/6.5.1/examples/kitchensink/?classic#binding-two-way) in the Kitchen Sink - this test clicks a button, which in-turn updates the text field's value (not being set directly in the test), then we assert that the value has changed:


describe('ValueChange', function() {
it('Should have an updated value in the text field after clicking the button', function() {
// Check initial text field value - it should be "The title"
stpo.BindingExample.titleField().value('The title');

// This button click causes the text field's value to update in the app
stpo.BindingExample.button().click();


// Text field value should have changed to a random value.
// Two methods:
stpo.BindingExample.titleField().expect('value').not.toEqual('The title');
stpo.BindingExample.titleField().valueNotLike('The title');
});
});


And the associated page object:



ST.pageobject.define('BindingExample', {
_locators: {
/**
* @method button
* @member stpo.BindingExample
* @return {ST.future.Button}
*/button: {
locator: 'button[text="Random Title"]',
name: 'button',
type: 'button',
className: 'ST.future.Button'
},
/**
* @method titleField
* @member stpo.BindingExample
* @return {ST.future.TextField}
*/titleField: {
locator: 'textfield[fieldLabel="Title"]',
name: 'titleField',
type: 'textField',
className: 'ST.future.TextField'
}
}
});