How to use _goBack 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.

BackNavigationButton.js

Source: BackNavigationButton.js Github

copy
1'use strict';
2
3import React, { Component, PropTypes } from 'react';
4import { StyleSheet, TouchableOpacity } from 'react-native';
5const Icon = require('react-native-vector-icons/EvilIcons');
6
7class BackNavigationButton extends Component {
8  static propTypes = {
9    onPress: PropTypes.func
10  }
11
12  static defaultProps = {
13    onPress: function() {}
14  }
15
16  constructor(props) {
17    super(props);
18    this._goBack = this._goBack.bind(this);
19  }
20
21  _goBack() {
22    if (this.props.navigator) {
23      this.props.navigator.pop();
24    } else {
25      this.props.onPress();
26    }
27  }
28
29  render() {
30    return (
31      <TouchableOpacity style={{backgroundColor: 'transparent'}} onPress={this._goBack}>
32        <Icon name='chevron-left' size={40} style={styles.leftNavIcon} >
33        </Icon>
34      </TouchableOpacity>
35    );
36  }
37}
38
39const styles = StyleSheet.create({
40  leftNavIcon: {
41    width: 40,
42    height: 40,
43    left: 5,
44    top: 5,
45    color: '#FF4081',
46  },
47});
48
49export default BackNavigationButton;
50
Full Screen

NavThreeScreens.js

Source: NavThreeScreens.js Github

copy
1'use strict';
2
3const React = require('react')
4
5const {
6  NavigationExperimental: Navigation,
7  View,
8  TouchableOpacity,
9  Text,
10  StyleSheet,
11  Platform,
12  BackAndroid,
13} = require('react-native')
14
15const {
16  CardStack: NavCardStack,
17  StateUtils: NavStateUtils,
18  Header: NavHeader,
19} = Navigation
20
21const Button = ({title, onPress}) => (
22  <TouchableOpacity onPress={onPress} style={styles.button}>
23    <View>
24      <Text>{title}</Text>
25    </View>
26  </TouchableOpacity>
27)
28
29const Screen1 = ({goScreen2, goScreen3}) => (
30  <View style={styles.sceneContainer}>
31    <Text>This is Screen1</Text>
32    <Button title="Go Screen2 &gt;" onPress={goScreen2} />
33    <Button title="Go Screen3 &gt;" onPress={goScreen3} />
34  </View>
35)
36
37const Screen2 = ({goBack, goScreen3}) => (
38  <View style={styles.sceneContainer}>
39    <Text>This is Screen2</Text>
40    <Button title="Go Screen3 &gt;" onPress={goScreen3} />
41    <Button title="&lt; Go Back" onPress={goBack} />
42  </View>
43)
44
45const Screen3 = ({goBack}) => (
46  <View style={styles.sceneContainer}>
47    <Text>This is Screen3</Text>
48    <Button title="&lt; Go Back" onPress={goBack} />
49  </View>
50)
51
52const reduceNavState = (navState, action) => {
53  const {type, key} = action;
54  switch (type) {
55    case 'push':
56      const route = {key}
57      return NavStateUtils.push(navState, route)
58    case 'pop':
59      return NavStateUtils.pop(navState)
60    default:
61      return navState
62  }
63}
64
65class NavExample extends React.Component {
66  constructor(props, context) {
67    super(props, context)
68    this.state = {
69      navigation: {
70        index: 0,
71        routes: [
72          {key: 'screen1'},
73        ]
74      }
75    }
76    this._renderScene = this._renderScene.bind(this)
77    this._renderHeader = this._renderHeader.bind(this)
78
79    this._goScreen2 = this._navigate.bind(this, {type:'push', key:'screen2'})
80    this._goScreen3 = this._navigate.bind(this, {type:'push', key:'screen3'})
81    this._goBack = this._navigate.bind(this, {type:'pop'})
82    if (Platform.OS === 'android') {
83      BackAndroid.addEventListener('hardwareBackPress', () => {
84        if (this.state.navigation.index > 0) {
85          this._goBack()
86          return true
87        } else {
88          return false
89        }
90      })
91    }
92  }
93  render() {
94    return (
95      <NavCardStack
96        renderScene={this._renderScene}
97        renderOverlay={this._renderHeader}
98        navigationState={this.state.navigation}
99        onNavigateBack={this._goBack}
100      />
101    )
102  }
103  _renderScene(sceneProps) {
104    // console.log(JSON.stringify(sceneProps, null, '  '));
105    const scene = sceneProps.scene.route.key
106    switch (scene) {
107      case 'screen1':
108        return (
109          <Screen1 goScreen2={this._goScreen2}
110            goScreen3={this._goScreen3}
111            {...sceneProps} />
112        )
113      case 'screen2':
114        return (
115          <Screen2 goBack={this._goBack}
116            goScreen3={this._goScreen3}
117            {...sceneProps} />
118        )
119      case 'screen3':
120        return (
121          <Screen3 goBack={this._goBack}
122            {...sceneProps} />
123        )
124      default:
125        return (
126          <View style={styles.sceneContainer}>
127            <Text>{`No such scene: ${scene}`}</Text>
128          </View>
129        )
130    }
131  }
132  _renderHeader(sceneProps) {
133    return (
134      <NavHeader {...sceneProps}
135        renderTitleComponent={() => (<NavHeader.Title>{sceneProps.scene.route.key}</NavHeader.Title>)}
136        onNavigateBack={this._goBack}
137        />
138    )
139  }
140  _navigate(action) {
141    const newNavState = reduceNavState(this.state.navigation, action)
142    if (newNavState !== this.state.navigation) {
143      this.setState({
144        navigation: newNavState,
145      })
146    }
147  }
148}
149
150const styles = StyleSheet.create({
151  sceneContainer: {
152    alignItems: 'center',
153    justifyContent: 'center',
154    flex: 1,
155  },
156  button: {
157    padding: 20,
158    marginTop: 20,
159    borderColor: 'black',
160    borderWidth: 1,
161    backgroundColor: 'white',
162  }
163})
164
165module.exports = NavExample
166
Full Screen

AppbarScreen.js

Source: AppbarScreen.js Github

copy
1import * as React from 'react';
2import { StyleSheet, View } from 'react-native';
3import { Appbar } from 'react-native-paper';
4import {useRoute,useNavigation,DrawerActions} from '@react-navigation/native';
5
6const AppbarScreen = ({navigation,searchcard,visibleform,...rest}) => {
7  // const _goBack = () => navigation.goBack();
8
9  
10
11  const _handleSearch = () => console.log('Searching');
12
13  const route = useRoute();
14  
15  const profilenavigation = useNavigation();
16  const _goBack = () => {
17    try{
18      if(navigation.canGoBack()){
19        navigation.goBack()
20      }else{
21        navigation.navigate('Explore')
22        // console.log(navigation.canGoBack())
23      }
24      
25    }catch(e){
26      navigation.navigate('Explore')
27    }
28  
29    
30  };
31  
32  
33  
34  // const _handleMore = () => {
35      
36        
37  //       profilenavigation.navigate('Videos');
38        
39      
40  //   };
41  //   const _handleMore1 = () => {
42          
43  //           profilenavigation.navigate('Articles')            
44            
45          
46          
47          
48        
49        
50  //     };
51
52  return (
53    <>
54    <Appbar.Header style={styles.header}>
55      <View style={{flex:1,flexDirection:'row',alignItems:'center',justifyContent:'space-between',color:'white'}}>
56        
57        {navigation.canGoBack() && route.name!="Explore" ?
58      <Appbar.BackAction color="white" onPress={_goBack} />: null}
59      {profilenavigation.canGoBack() ? 
60      <Appbar.Content {...rest} onPress={_goBack} />: <Appbar.Content {...rest} />
61      }
62      
63
64      {searchcard &&
65      <Appbar.Action color="white" icon={visibleform?'close':'magnify'} onPress={()=>searchcard()} />}
66      
67      {/* <Appbar.Action color="white" icon="view-headline" onPress={_handleMore1} /> */}
68      {/* {route.name !== "Home"  &&
69      <Appbar.Action icon="cog-outline" onPress={_handleMore1} />} */}
70      </View>
71    </Appbar.Header>
72    
73    </>
74  );
75};
76
77export default AppbarScreen;
78
79const styles = StyleSheet.create({
80    header: {
81      position: 'relative',
82      left: 0,
83      right: 0,
84      // top: 0,
85      height:50,
86      backgroundColor:"rgba(3, 13, 81, 0.9)"
87    },
88  });
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)