代码之家  ›  专栏  ›  技术社区  ›  Emna Ayadi

使用appium执行量角器脚本时等待异步脚本结果超时

  •  5
  • Emna Ayadi  · 技术社区  · 8 年前

    在量角器中运行多个测试时出现问题:60010秒后等待异步脚本结果超时 登录脚本之后执行的教程脚本的代码: Here the code of login script + Tutorial script

    下面是我在配置文件中使用的代码 A Code proposed in another question 但这并没有解决我的问题!

    onPrepare: function() {
      return browser.getProcessedConfig().then(function(config) {
        var browserName = config.capabilities.browserName;
        browser.manage().timeouts().setScriptTimeout(60000);
    
      });
    

    Here the config file

    PS:即使我为元素输入了错误的位置,我也会出现超时错误,而不是无法找到此元素!就好像“点击教程按钮”这行代码从未执行过一样

    • 是因为教程调用了ajax吗?

    Error 这里是我的html代码:

    </div></md-card-content> </md-card><!-- end ngIf: !expandChart --> </div> </div> </div></md-content> </div></div> <!-- Google Analytics: change UA-XXXXX-X to be your site's ID --> <!--<script>--> <!--!function(A,n,g,u,l,a,r){A.GoogleAnalyticsObject=l,A[l]=A[l]||function(){--> <!--(A[l].q=A[l].q||[]).push(arguments)},A[l].l=+new Date,a=n.createElement(g),--> <!--r=n.getElementsByTagName(g)[0],a.src=u,r.parentNode.insertBefore(a,r)--> <!--}(window,document,'script','https://www.google-analytics.com/analytics.js','ga');--> <!--ga('create', 'UA-XXXXX-X');--> <!--ga('send', 'pageview');--> <!--</script>--> <script src="scripts/vendor.js"></script> <script src="cordova.js"></script> <script src="scripts/scripts.js"></script> <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha1.js"></script> <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js"></script> <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script> <div class="introjs-overlay" style="top: 0;bottom: 0; left: 0;right: 0;position: fixed;opacity: 0.8;"></div><div class="introjs-helperLayer " style="width: 538px; height:366px; top:64px;left: 195px;"></div><div class="introjs-tooltipReferenceLayer" style="width: 538px; height:366px; top:64px;left: 195px;"><div class="introjs-tooltip" style="left: 546px;"><div class="introjs-tooltiptext">Watchlist view. Swipe the row in the grid to the left to show the delete action.</div><div class="introjs-bullets"><ul><li><a class="active" href="javascript:void(0);" data-stepnumber="1">&nbsp;</a></li><li><a href="javascript:void(0);" data-stepnumber="2">&nbsp;</a></li><li><a href="javascript:void(0);" data-stepnumber="3">&nbsp;</a></li><li><a href="javascript:void(0);" data-stepnumber="4">&nbsp;</a></li><li><a href="javascript:void(0);" data-stepnumber="5">&nbsp;</a></li><li><a href="javascript:void(0);" data-stepnumber="6">&nbsp;</a></li><li><a href="javascript:void(0);" data-stepnumber="7">&nbsp;</a></li><li><a href="javascript:void(0);" data-stepnumber="8">&nbsp;</a></li></ul></div><div class="introjs-progress" style="display: none;"><div class="introjs-progressbar" style="width:12.5%;"></div></div><div class="introjs-arrow left" style="display: inherit;"></div><div class="introjs-tooltipbuttons"><a class="introjs-button introjs-skipbutton" href="javascript:void(0);">Don't show it again!</a><a href="javascript:void(0);" class="introjs-button introjs-prevbutton introjs-disabled" tabindex="-1">Previous</a><a href="javascript:void(0);" class="introjs-button introjs-nextbutton">Next</a></div></div></div></body></html>​
    

    Appium log

    4 回复  |  直到 7 年前
        1
  •  3
  •   Linh Pham    8 年前

    1.关于路线检查

    如果在第一次规范之后,用户登录并更改了路由。确保在执行任何测试之前都导航了所有内容。

    expect(browser.getCurrentUrl()).toContain('#/the_route_of_logged_in'); 
    // '#/' is just illustration. You can remove it to make it shorter
    // => like this ...toContain('the_route_of_logged_in');
    

    2.关于点击教程

    browser.wait(EC.elementToBeClickable(tutorial), 10000);
    

    执行 browser.wait 在尝试点击之前,先用EC点击可点击按钮(看起来你在这里有很好的方法)

    =>;总结 您可以尝试一下:

    'user strict';
    
    var EC = protractor.ExpectedConditions;
    
    describe('tutorials', function () {
    
        it('should make click into tutorial button', function () {
    
            expect(browser.getCurrentUrl()).toContain('the_route_of_logged_in');
    
            var tutorial = $('.introjs-nextbutton'); 
            browser.wait(EC.elementToBeClickable(tutorial), 8000, 'Timed out');
            tutorial.click();
    
            browser.sleep(8080); // regardless we are not reaching this point. But I will suggest to reduce this sleep time like 1000 (1s).
        });
    });
    

    3.(可选)如果上述两点没有帮助

    在您的所有规格中 login-spec.js tutorial-spec.js 添加 process.nextTick(done); 在一个 afterAll() 阻止以确保没有任何Jasmine Reporters在规格后被卡住。

    describe('foo', function(){
    
      afterAll(function(done){
        process.nextTick(done);
      });  
    
      it('should bar...', function() {});
    }
    

    附笔。 请注意,我完全不知道我的建议/方法是否有帮助。由于使用e2e测试进行调试总是很痛苦……因为我们总是不知道“错误来自哪里”。所以我能做的就是给你建议。 (有时我花了几个小时来观察浏览器的行为,以确定e2e测试的问题)

    不复制粘贴 我的代码到你的代码中。我用你提供的图片输入了它,我可以在那里输入一些错误。

        2
  •  2
  •   Hikaryu    8 年前

    在capabilities下向conf.js添加参数:

    maxSessions: 1,
    

    这应该会有所帮助。 此外,您的超时间隔可能太高,30000应该足够了。

    或在准备变更行上:

    browser.manage().timeouts().implicitlyWait(5000);
    

    @编辑: 更改为类似于此的内容时发现类似于以下内容

    1. baseUrl是10.0.2.2,而不是localhost,因为它用于访问android中主机的localhost 模拟器/设备
    baseUrl: 'http://10.0.2.2:' + (process.env.HTTP_PORT || '8000'),
    

    新命令的功能:

     newCommandTimeout: 60
    

    此外,使用承诺可能会有帮助,而不是超时

    someethingToDo.click().then(function(){
    
      return somethingToDo.click();
    
    }).then(function(){
        //morecode
    });
    
        3
  •  2
  •   finspin    8 年前

    我想你可能对如何设置超时有问题。从配置文件中删除所有超时引用,然后尝试如下操作(根据需要进行相应调整以包括其他配置):

    exports.config = {
        allScriptsTimeout: 60000,
        getPageTimeout: 30000,
        jasmineNodeOpts: {
            defaultTimeoutInterval: 62000,
        }
    }
    
        4
  •  2
  •   Emna Ayadi    8 年前

    最后,我试图通过添加此回拨来解决我的问题

    describe("long asynchronous specs", function() {
        beforeEach(function(done) {
          done();
        }, 10000);
        });
    

    这是茉莉花的链接 Asynchronous_Support 这有助于我理解超时问题。 希望能对你有所帮助,