How to use _goForward method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

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

ShuffleManager.js

Source: ShuffleManager.js Github

copy
1/* ShuffleManager
2 *
3 * Manages navigation throughout a list which is:
4 * - Sourced from another provided list
5 * - In random order (except to avoid consecutive duplicates)
6 * - Extended endlessly on-the-fly, as needed
7 * - Able to have future history overwritten by non-random choices
8 * - Able to swap source lists and maintain shuffle order for common members
9 */
10
11export class ShuffleManager {
12  constructor(list, options = {}) {
13    this._list = list;
14    this._forwardStack = [];
15    this._backStack = [];
16    this._currentItem = undefined;
17
18    this._allowBackShuffle = Boolean(options.allowBackShuffle);
19  }
20
21  findNextItem(currentIndex) {
22    if (currentIndex !== undefined) {
23      this.setCurrentIndex(currentIndex);
24    }
25    this._currentItem = _findNextItem(
26      this._list,
27      this._forwardStack,
28      this._backStack,
29      this._currentItem,
30      true
31    );
32    return this._currentItem;
33  }
34
35  findPreviousItem(currentIndex) {
36    if (currentIndex !== undefined) {
37      this.setCurrentIndex(currentIndex);
38    }
39    this._currentItem = _findNextItem(
40      this._list,
41      this._backStack,
42      this._forwardStack,
43      this._currentItem,
44      this._allowBackShuffle
45    );
46    return this._currentItem;
47  }
48
49  pickNextItem(index, currentIndex) {
50    if (currentIndex !== undefined) {
51      this.setCurrentIndex(currentIndex);
52    }
53    if (this._list[index] === undefined) {
54      return undefined;
55    }
56    if (this._currentItem !== undefined) {
57      this._backStack.push(this._currentItem);
58    }
59    this._forwardStack.length = 0;
60    this._currentItem = this._list[index];
61    return this._currentItem;
62  }
63
64  setList(list) {
65    this._list = list;
66  }
67
68  setOptions(options) {
69    for (const o of Object.keys(options)) {
70      switch (o) {
71        case 'allowBackShuffle':
72          this[`_${o}`] = Boolean(options[o]);
73          break;
74        default:
75          break;
76      }
77    }
78  }
79
80  setCurrentIndex(currentIndex) {
81    const item = this._list[currentIndex];
82    if (this._currentItem !== item) {
83      this.clear();
84      this._currentItem = item;
85    }
86  }
87
88  clear() {
89    this._forwardStack.length = 0;
90    this._backStack.length = 0;
91    this._currentItem = undefined;
92  }
93}
94
95function _goForward(n, forwardStack, backStack, currentItem) {
96  let item = currentItem;
97  for (let i = 0; i < n; i++) {
98    if (!forwardStack.length) {
99      // rollback before erroring (note stack reversal)
100      _goForward(i, backStack, forwardStack, item);
101      throw `Moving ${n} places was not possible!`;
102    }
103    backStack.push(item);
104    item = forwardStack.pop();
105  }
106  return item;
107}
108
109function _allItemsMatch(list, item) {
110  if (!list.length) {
111    return false;
112  }
113  for (let i = 0; i < list.length; i++) {
114    if (item !== list[i]) {
115      return false;
116    }
117  }
118  return true;
119}
120
121function _findNextItem(list, forwardStack, backStack, currentItem, allowMore) {
122  let item = currentItem;
123  if (!list.length) {
124    return undefined;
125  }
126  for (let i = 1; i <= forwardStack.length; i++) {
127    if (list.indexOf(forwardStack[forwardStack.length - i]) !== -1) {
128      return _goForward(i, forwardStack, backStack, item);
129    }
130  }
131  if (!allowMore) {
132    return undefined;
133  }
134  if (_allItemsMatch(list, item)) {
135    // we can serve this as our "next" item but we
136    // won't modify our history since it's the same.
137    return item;
138  }
139  let nextItem;
140  do {
141    nextItem = list[Math.floor(Math.random() * list.length)];
142  } while (item === nextItem || nextItem === undefined);
143  // if we're skipping items that aren't in our current list we may
144  // have some items in our forwardStack - make sure we move to the front.
145  item = _goForward(forwardStack.length, forwardStack, backStack, item);
146  if (item !== undefined) {
147    backStack.push(item);
148  }
149  return nextItem;
150}
151
152export default ShuffleManager;
153
Full Screen

browser.js

Source: browser.js Github

copy
1/**
2 * Created by apple on 16/2/17.
3 */
4
5'use strict';
6
7import React, {
8    Component,
9    StyleSheet,
10    View,
11    WebView,
12    TouchableOpacity,
13    Text,
14    PropTypes
15} from 'react-native';
16
17var styles = StyleSheet.create({
18    container: {
19        flex: 1
20    },
21    tool: {
22        flexDirection: 'row',
23        justifyContent: 'space-around',
24        height: 35,
25        alignItems: 'center',
26        borderTopColor: '#bcbac1',
27        borderTopWidth: 1
28    },
29    btn: {
30        padding: 10
31    }
32});
33
34var WEBVIEW_REF = 'webview';
35
36/**
37 * 简单网页浏览器
38 */
39export default class Browser extends Component {
40    propTypes: {
41        url: PropTypes.string.isRequired
42        };
43
44    render() {
45        let canGoBack = this.state !== null && this.state.canGoBack;
46        let canGoForward = this.state !== null && this.state.canGoForward;
47        let loading = this.state !== null && this.state.loading;
48        return (
49            <View style={styles.container}>
50                <WebView
51                    ref={WEBVIEW_REF}
52                    source={{uri: this.props.url}}
53                    startInLoadingState={true}
54                    onNavigationStateChange={ state => this._onNavigationStateChange(state)}
55                />
56                <View style={styles.tool}>
57                    <TouchableOpacity onPress={() => this._goBack()} style={styles.btn}>
58                        <Text style={{color:canGoBack?'#333':'#dedede'}}>{'<后退'}</Text>
59                    </TouchableOpacity>
60                    <Text>{loading === false ? '加载完毕' : '加载中'}</Text>
61                    <TouchableOpacity onPress={() => this._goForward()} style={styles.btn}>
62                        <Text style={{color:canGoForward ?'#333':'#dedede'}}>{'前进>'}</Text>
63                    </TouchableOpacity>
64                </View>
65            </View>
66        );
67    }
68
69    _onNavigationStateChange(state) {
70        this.setState(state);
71    }
72
73    _goBack() {
74        this.refs[WEBVIEW_REF].goBack();
75    }
76
77    _goForward() {
78        this.refs[WEBVIEW_REF].goForward();
79    }
80};
Full Screen

USA_intro.js

Source: USA_intro.js Github

copy
1Dendrochronology.USA_intro = function(game) {
2	this.game = game; // keep reference to main game object
3	var helpDialogSize = {width:700, height:300};
4	GameLevel.call(this, 21, 'wood_grain_bg_3', helpDialogSize);
5};
6
7Dendrochronology.USA_intro.prototype = Object.create(GameLevel.prototype);
8Dendrochronology.USA_intro.prototype.constructor = Dendrochronology.USA_intro;
9
10Dendrochronology.USA_intro.prototype.create = function() {
11	GameLevel.prototype.create.apply(this);
12	this.buildLevel();
13};
14
15Dendrochronology.USA_intro.prototype.buildLevel = function() {
16	// Button to move forward to the next screen/level (Skip Intro)
17	var xLoc = this.game.width - 260;
18	var yLoc = this.game.height - 60;
19	this._forwardBtn = this.add.button(xLoc, yLoc, 'skip_intro_btn_spritesheet', this._goForward, this, 1, 0, 2, 0);
20    this._forwardBtn.name = 'forwardButton';
21
22
23	// Button to move forward to the next screen/level (Continue)
24	this._continueBtn = this.add.button(xLoc, yLoc, 'continue_btn_spritesheet', this._goForward, this, 1, 0, 2, 0);
25    this._continueBtn.name = 'continueButton';
26	this._continueBtn.visible = false;
27
28	this._initSlideShow();
29};
30
31Dendrochronology.USA_intro.prototype.preload = function () {
32    // load the JSON data file with formatting for the Slide Show
33    this._slideShowData = this.cache.getJSON('slideShowData');
34		this._dialog = this.cache.getJSON('dialog');
35};
36
37Dendrochronology.USA_intro.prototype._initSlideShow = function () {
38    var config = this._slideShowData.slideShowUSA;
39	this._slideShow = new SlideShow(this, config);
40	//this._slideShow.x = 100;
41	//this._slideShow.y = 200;
42};
43
44Dendrochronology.USA_intro.prototype._goForward = function (pointer) {
45    // Go forward to next screen/level
46	// Go to USA Collect Samples level
47	//this._selectedLevel = 22;
48    this.state.start('GameLevel_22');
49};
50
51// Public Methods
52Dendrochronology.USA_intro.prototype.lastSlide = function (trueFalse) {
53	this._continueBtn.visible = trueFalse;
54	this._forwardBtn.visible = !trueFalse;
55};
56
57
58Dendrochronology.USA_intro.prototype.goForward = function () {
59    // Go forward to next screen/level
60	// Go to USA Collect Samples level
61	this.state.start('GameLevel_22');
62};
63
64// Close Credits and Help dialog boxes if open (visible)
65Dendrochronology.USA_intro.prototype.closeDialogs = function () {
66    this._helpDialogBox.visible = false;
67	this._creditsDialogBox.visible = false;
68}
69
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 Playwright Internal 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)