Results 1 to 10 of 10

Thread: Trying to find a way to test for the non-existence of an object through sencha test

  1. #1

    Join Date
    Jan 2018
    Posts
    13
    Answers
    1

    Default Answered: Trying to find a way to test for the non-existence of an object through sencha test

    The scenario I'm trying to solve for is that when certain elements exist for a logged in account, this object exists in a tree-list item. However, when those elements are NOT there, the item is not on the tree-list, and I do not know how to test for this expected absence of this object.

    Trying to find any element on the object fails because the test times out waiting for the object to appear. Even a try/catch fails and cancels the test without successful failure.

    Anyone have other ideas on this type of negative test?

  2. It looks like there is a known issue with the "timedout()" API, when it's the first event in a spec/test. This will be fixed in a future update. Also, in your code sample above, the last two lines are invalid usage of the Sencha Test APIs. The first two lines are valid syntax.

    In order to test for non-existence of a component, here are two examples that will work in the meantime:

    Code:
        it('Should pass as component does not exist', function () {
            ST.component('#invalidComponent');
            
            // Expect a failure to occur on this individual test.  If there is a failure, this will cause the spec to show as a "pass".
            // It's best to keep the scope of the test fairly small, to just the failure you want to test.
            ST.expectFailure();    
        });
        
        it('Should also pass as component does not exist', function () {
            // Make use of the "wait" API, so the "timedout" API is not the first event in the spec.
            ST.wait(1);
            
            ST.component('#invalidComponent').timedout();
        });

  3. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    325
    Answers
    49

    Default

    You can use the "timedout()" API to assert that a component or element does not exist. For example:

    Code:
    it('Should not find a grid', function() {
        ST.grid('my-grid').timedout();    // This test will pass if the grid does not exist
    });
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  4. #3

    Join Date
    Jan 2018
    Posts
    13
    Answers
    1

    Default

    Dan, I noticed that function in the API but the ST program does not seem to recognize it.

    Just to be sure, i tried all 4 of these to try and verify that the tree-list item is not in the tree-list as expected. The component is the one I successfully use to click on the element when it is supposed to be available.
    Code:
        // ST.component('treelistitem[text="Timesheets"]').timedout();
        // ST.element('treelistitem[text="Timesheets"]').timedout();
        // ST.component(ST.component('treelistitem[text="Timesheets"]')).timedout();
        ST.component(ST.component('treelistitem[text="Timesheets"]')).Timedout();
    the first two give an error about an object not being set, the third gives a timedout error result in the summary, and the last says it is not a function at object<anonymous>.

    I was hoping i was misreading the API on this one, but it looks like timedout() is not working as expected in ST.

  5. #4

    Join Date
    Jan 2018
    Posts
    13
    Answers
    1

    Default

    Forgot to put in here that i'm using Sencha Test 2.1.2.2 with the alterations to allow Chrome 65 to work. This is on a windows 10 machine.

  6. #5
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    325
    Answers
    49

    Default

    It looks like there is a known issue with the "timedout()" API, when it's the first event in a spec/test. This will be fixed in a future update. Also, in your code sample above, the last two lines are invalid usage of the Sencha Test APIs. The first two lines are valid syntax.

    In order to test for non-existence of a component, here are two examples that will work in the meantime:

    Code:
        it('Should pass as component does not exist', function () {
            ST.component('#invalidComponent');
            
            // Expect a failure to occur on this individual test.  If there is a failure, this will cause the spec to show as a "pass".
            // It's best to keep the scope of the test fairly small, to just the failure you want to test.
            ST.expectFailure();    
        });
        
        it('Should also pass as component does not exist', function () {
            // Make use of the "wait" API, so the "timedout" API is not the first event in the spec.
            ST.wait(1);
            
            ST.component('#invalidComponent').timedout();
        });
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  7. #6

    Join Date
    Jan 2018
    Posts
    13
    Answers
    1

    Default

    the ST.expectFailure(); example fixed my issue. The example of this in the API doesnt make this process clear, but your example here is what made this check work great.

    Thank you.

  8. #7

    Default

    Hi, well this does not work in my simple scenario.
    Yes, if I delete a record, and it's not longer present in a grid, such test will fail and report success due to "expected failure":

    Code:
         
    it("Record should not exists", function(){
             ST.grid('mygrid')
                .rowWith('value', myValue);
              
            ST.expectFailure();
         });
    But.... if I remove the delete code, so the record remains in place, what I will get is:

    Failed with error "Cannot read property 'length' of null"
    Expected test to have failures

    As a result, this is still, incorrect, reported as success.
    So, what did fail here?

    Even this alone will report success! Isn't that a bug in ST?
    I believe this should NOT pass, as there are no failures:
    Code:
         
    it("Record should not exists", function(){
            ST.expectFailure();
    });

  9. #8

    Default

    I want to post another example, taken directly from the docs....

    Code:
     describe('failures', function () {     it('should pass', function () {
             expect(1).toBe(2);
             ST.expectFailure();
         });
     });
    
    
    
    Actual result:
    FAIL: Expected 1 to be 2. (ok)
    FAIL: Failed with error "Cannot read property 'isRegex' of undefined" (should not be here...?)
    SUCCESS: Expected test to have failures (ok, because our 'expect' failed)
    
    
    =============================================
    describe('no failures', function () {
         it('should pass', function () {
             expect(1).toBe(1);
             ST.expectFailure();
         });
     });
     
    Actual result:
    SUCCESS: Expected 1 to be 1. (ok)
    FAIL: Failed with error "Cannot read property 'isRegex' of undefined" (should not be here)
    SUCCESS: Expected test to have failures (WRONG: ST error caused 'expect failure' to succeed)
    
    
    =============================================
    
    
    describe('failures', function () {
         it('should pass', function () {
             ST.expectFailure();
         });
     });
    
    Actual result:
    FAIL: Failed with error "Cannot read property 'length' of null" should not be here)
    SUCCESS: Expected test to have failures(WRONG: ST error caused expected failure to succeed, but there are no failures in the test)

  10. #9
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    325
    Answers
    49

    Default

    @maciej.zabielski: We'll log a bug regarding the "ST.expectFailure" issue. It seems to only be a problem if no other "ST." API calls are made before calling "ST.expectFailure()".

    In the latest release of Sencha Test (2.2.1), the "timedout" API has some improvements, so the following could be used instead:

    Code:
    ST.grid('array-grid')
        .rowAt(300)
        .timedout();    // Expect the previous action to cause a timeout (row not found)
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  11. #10

    Default

    Hi Daniel,

    I have an open ticket for that #46757.
    As I have said, I also had problems with this (so when there is another ST call before)
    Code:
    it("Record should not exists", function(){  
           ST.grid('mygrid')
             .rowWith('value', myValue);
              
            ST.expectFailure();
      });

    The result will be fine, if there is a failure in rowWith. It will not work if the row is found, and will end up with:
    Failed with error "Cannot read property 'length' of null"

    As a result, the test will also pass while it should not, as the row was found.

    For me .timedout(); does not work either!

    Test case:
    1) do not delete record and run this, test should pass

    Code:
        it("Domain should not exists", function(){
             ST.grid('tdxmmasterview tdxmdomainsview')
                .rowWith('domainId', domainId);           
         });
    OK - Test passed. Expected: pass


    2) delete a record and run this, test should fail:
    Code:
        it("Domain should not exists", function(){
             ST.grid('tdxmmasterview tdxmdomainsview')
                .rowWith('domainId', domainId);           
         });
    OK - Test failed. Expected: fail (timeout looking for record)

    3) delete a record and run this, test should pass:
    Code:
       
      it("Domain should not exists", function(){        
          ST.grid('tdxmmasterview tdxmdomainsview')
                .rowWith('domainId', domainId)
                .timedout();
         });

    OK - Test passed. Expected: pass
    expected timeout waiting for event to be ready for ST.future.Row

    4) do NOT delete a record and run this, test should fail (record exists, but we required timeout)
    Code:
       
     it("Domain should not exists", function(){         
           ST.grid('tdxmmasterview tdxmdomainsview')
                .rowWith('domainId', domainId)
                .timedout();
         });

    FAIL - Test passed. Expected: fail

    Am I wrong?

Similar Threads

  1. Replies: 1
    Last Post: 3 Feb 2017, 8:59 AM
  2. Replies: 5
    Last Post: 2 Feb 2017, 8:42 AM
  3. Replies: 5
    Last Post: 26 Sep 2016, 11:17 AM
  4. Replies: 1
    Last Post: 9 Aug 2016, 3:46 AM
  5. Replies: 2
    Last Post: 4 Aug 2016, 4:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •