How to use performCleanup method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

carga.js

Source: carga.js Github

copy
1const expireTime = 60000
2
3class Carga {
4    constructor() {
5        this.currentHistory = [];
6        this.lastReceived = new Date().getTime();
7        this.chargeMean = 0;
8
9        // this.addCurrents = this.addCurrents.bind(this);
10        // this.performCleanup = this.performCleanup.bind(this);
11        // this.restart = this.restart.bind(this);
12        // this.getCharge = this.getCharge.bind(this);
13    }
14
15    addCurrents(currents) {
16        let sum = (this.normalizeValue(parseInt(currents[0])) + this.normalizeValue(parseInt(currents[2])) + this.normalizeValue(parseInt(currents[3])))/10;
17        let timestamp = new Date().getTime();
18
19        if (timestamp - this.lastReceived >= expireTime) {
20            this.restart();
21        }
22        this.performCleanup(timestamp);
23        this.currentHistory.push({current: sum, timestamp: timestamp});
24        this.lastReceived = timestamp;
25
26        let i;
27        let charge = 0;
28        for (i = 0; i < this.currentHistory.length-1; i++) {
29            charge += (this.currentHistory[i+1].current+this.currentHistory[i].current)/2*((this.currentHistory[i+1].timestamp-this.currentHistory[i].timestamp)/1000);
30        }
31
32        this.chargeMean = charge;
33
34    }
35
36    performCleanup(now) {
37        let firstIndex = 0;
38        for (firstIndex = 0; firstIndex<this.currentHistory.length; firstIndex++) {
39            if (now - this.currentHistory[firstIndex].timestamp < expireTime)
40                break;
41        }
42        if (firstIndex > 0)
43            this.currentHistory = this.currentHistory.slice(firstIndex);
44    }
45
46
47    restart() {
48        this.currentHistory = []
49        this.chargeMean = 0;
50    }
51
52    getChargeMean() {
53        return this.chargeMean;
54    }
55
56    normalizeValue(value) {
57        return (value > Math.pow(2, 15) ? (value-Math.pow(2, 16)): value)
58    }
59}
60
61module.exports = Carga;
Full Screen

release_continuationpoints_test.js

Source: release_continuationpoints_test.js Github

copy
1/*global UaNodeId, readSetting, GetDefaultReferencesFromNodeId, Session, addError,
2  GetBrowseResponseForOneReference, BrowseNextFromResponseAndAssertReferencesMatch,
3  StatusCode, AssertFalse
4*/
5
6
7function TestBrowseNextWhenMoreReferencesExist( doReleaseContinuationPoints, performCleanup )
8{
9    var nodeToBrowse = UaNodeId.fromString( readSetting( "/Server Test/NodeIds/References/Has 3 Forward References 1" ).toString() );
10    if( nodeToBrowse === undefined || nodeToBrowse === null )
11    {
12        addSkipped( "[Configuration Issue?] Unable to conduct test. Check setting '/Server Test/NodeIds/References/Has 3 Forward References 1'." );
13        return;
14    }
15
16    // get expected references
17    var expectedReferences = GetDefaultReferencesFromNodeId( Session, nodeToBrowse );
18    if( expectedReferences.length < 3 )
19    {
20        addError( "Test cannot be completed: node must have at least three references." );
21        return;
22    }
23    
24    // Browse for first reference
25    var firstResponse = GetBrowseResponseForOneReference( Session, [ nodeToBrowse ] );
26    if( firstResponse === -1 )
27    {
28        return -1;
29    }
30    
31    // BrowseNext for second reference
32    // And validate that the reference from BrowseNext is the second reference (expectedReferences[1])
33    var response = BrowseNextFromResponseAndAssertReferencesMatch( [ expectedReferences ], 1, 1, doReleaseContinuationPoints, firstResponse.Results );
34
35    // Validate the releaseContinuationPoints = false case; the true case is covered within the above function
36    if( !doReleaseContinuationPoints )
37    {
38        if( response.Results.length > 0 )
39        {
40            var result = response.Results[0];
41            
42            if( StatusCode.Good !== result.StatusCode.StatusCode )
43            {
44                addError( "StatusCode from BrowseNext is not Good: " + result.StatusCode, result.StatusCode );
45            }
46            if( AssertFalse( result.ContinuationPoint.isEmpty(), "ContinuationPoint is empty: " + result.ContinuationPoint ) )
47            {
48                BrowseNextFromResponseAndAssertReferencesMatch( [ expectedReferences ], 2, 2, doReleaseContinuationPoints, response.Results );
49            }
50        }
51    }
52
53    // perform clean-up?
54    if( performCleanup !== undefined && performCleanup !== null && performCleanup === true )
55    {
56        releaseContinuationPoints( Session, response );
57    }
58
59    return [ firstResponse, response ];
60}
61
62
63// release ContinuationPoints returned in a response; no result checking
64function releaseContinuationPoints( session, browseResponse )
65{
66    var request = CreateDefaultBrowseNextRequest( session );
67    var response = new UaBrowseNextResponse();
68    request.ReleaseContinuationPoints = true;
69    for( var i = 0; i < browseResponse.Results.length; i++ )
70    {
71        request.ContinuationPoints[i] = browseResponse.Results[i].ContinuationPoint;
72    }
73    session.browseNext( request, response );
74}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Xcuitest Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)