How to use driver.active 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
_

HomePage.js

Source: HomePage.js Github

copy
1import React, { Component } from "react";
2import DriverHeader from "./DriverHeader";
3import DriverInactive from "./DriverInactive";
4import DriverActiveNoRide from "./DriverActiveNoRide";
5import DriverActiveOnRide from "./DriverActiveOnRide";
6
7export default class HomePage extends Component {
8  constructor(props) {
9    super(props);
10    this.state = {};
11  }
12
13  render() {
14    let relevantView;
15    const activeRides = this.props.user.driverData.rides.filter(
16      ride =>
17        ride.ride_status !== "waiting_on_driver" &&
18        ride.ride_status !== "complete"
19    );
20    const driverActive = this.props.user.driverData.active;
21
22    if (!driverActive && !activeRides.length) {
23      relevantView = (
24        <DriverInactive
25          user={this.props.user}
26          usrUpdate={this.props.usrUpdate}
27          refreshUserData={this.props.refreshUserData}
28          usrLoading={this.props.usrLoading}
29        />
30      );
31    } else if (activeRides.length > 0) {
32      relevantView = (
33        <DriverActiveOnRide
34          user={this.props.user}
35          currentRide={activeRides[0]}
36          refreshUserData={this.props.refreshUserData}
37          usrLoading={this.props.usrLoading}
38        />
39      );
40    } else if (driverActive) {
41      relevantView = (
42        <DriverActiveNoRide
43          user={this.props.user}
44          usrUpdate={this.props.usrUpdate}
45          refreshUserData={this.props.refreshUserData}
46          usrLoading={this.props.usrLoading}
47        />
48      );
49    }
50    return (
51      <>
52        <DriverHeader user={this.props.user} />
53        {relevantView}
54      </>
55    );
56  }
57}
58
Full Screen

getAllDriver.js

Source: getAllDriver.js Github

copy
1const { toKiloMeter } = require('../helpers//toKm')
2const { consumer } = require('../libs/kafka')
3
4exports.getAllDrivers = function (io, socket, db) {
5	socket.on(`client:send`, async (userId) => {
6		let getOrderByMitra = await db('order')
7			.select('*', db.raw('to_json(location) as location'), db.raw('to_json(location) as destination'))
8			.where('customer_id', userId)
9			.andWhere('status', 'pesanan menunggu konfirmasi')
10			.andWhere('order_date', '>=', `${new Date().toLocaleDateString()}T00:00:00.00Z`)
11			.first()
12
13		let getAllDriverActive = []
14
15		if (getOrderByMitra) {
16			// get data from datase if user reloading data
17			if (!getAllDriverActive.length) {
18				getAllDriverActive = await db('point_location')
19					.select('id', 'driver_id', 'active', 'latitude', 'longitude')
20					.where('active', true)
21
22				const newGetAllDriverActive = getAllDriverActive
23					.map((val) => {
24						const latitude = parseFloat(getOrderByMitra.location.latitude)
25						const longitude = parseFloat(getOrderByMitra.location.longitude)
26
27						return toKiloMeter(latitude, longitude, val.latitude, val.longitude) <= 10 ? val : false
28					})
29					.filter((val) => typeof val != 'boolean')
30
31				io.emit(`server:send:${userId}`, JSON.stringify(newGetAllDriverActive))
32			}
33
34			// get data from kafka if user not reloading data
35			await consumer('pointLocation', async ({ topic, partition, message }) => {
36				const streamingPayload = message.value.toString()
37				getAllDriverActive = JSON.parse(streamingPayload)
38
39				const newGetAllDriverActive = getAllDriverActive
40					.map((val) => {
41						const latitude = parseFloat(getOrderByMitra.location.latitude)
42						const longitude = parseFloat(getOrderByMitra.location.longitude)
43
44						return toKiloMeter(latitude, longitude, val.latitude, val.longitude) <= 10 ? val : false
45					})
46					.filter((val) => typeof val != 'boolean')
47
48				io.emit(`server:send:${userId}`, JSON.stringify(newGetAllDriverActive))
49			})
50		}
51	})
52}
53
Full Screen

DriverActiveNoRide.js

Source: DriverActiveNoRide.js Github

copy
1import React, { Component } from "react";
2import Grid from "@material-ui/core/Grid";
3import DriverHUD from "./DriverHUD";
4import DriverActiveRides from "./DriverActiveRides";
5
6export default class DriverActiveNoRide extends Component {
7  constructor(props) {
8    super(props);
9    this.state = {};
10  }
11
12  render() {
13    return (
14      <div style={{ padding: "50px" }}>
15        <Grid
16          container
17          direction="row"
18          justify="space-around"
19          alignItems="flex-start"
20          spacing={24}
21        >
22          <Grid item xs={12} sm={6}>
23            <DriverHUD
24              user={this.props.user}
25              usrUpdate={this.props.usrUpdate}
26              usrLoading={this.props.usrLoading}
27            />
28          </Grid>
29          <Grid item xs={12} sm={6}>
30            <DriverActiveRides
31              user={this.props.user}
32              usrUpdate={this.props.usrUpdate}
33              refreshUserData={this.props.refreshUserData}
34            />
35          </Grid>
36        </Grid>
37      </div>
38    );
39  }
40}
41
Full Screen

DriverActiveMenu.js

Source: DriverActiveMenu.js Github

copy
1import React from "react";
2import "./DriverActiveMenu.css";
3import DriverActiveOptions from "./DriverActiveOptions/DriverActiveOptions";
4import DriverPausedOptions from './DriverPausedOptions/DriverPausedOptions';
5
6export default class DriverActiveMenu extends React.Component{
7    constructor(props){
8        super(props);
9        this.state = {
10            paused: false,
11            loading: false
12        }
13    }
14
15    toggleDriverActiveMenu = ()=>{
16        const driverActivemenu = document.getElementById("driver-active-menu-container");
17
18        driverActivemenu.classList.toggle("open-driver-active-menu");
19    }
20
21    toggleLoading = ()=>{
22        this.setState({
23            laoding: !this.state.loading
24        });
25    }
26
27    togglePaused = ()=>{
28        this.setState({
29            paused: !this.state.paused
30        });
31    }
32
33    render(){
34        
35        return (
36            <section id="driver-active-menu-container">
37                {!this.state.paused ? <DriverActiveOptions history={this.props.history} toggleLoading={this.toggleLoading} togglePaused={this.togglePaused} toggleDriverActiveMenu={this.toggleDriverActiveMenu}/> : ""}
38                {this.state.paused ? <DriverPausedOptions toggleLoading={this.toggleLoading} togglePaused={this.togglePaused} toggleDriverActiveMenu={this.toggleDriverActiveMenu}/> : ""}
39            </section>
40        );
41    };
42};
Full Screen

DriverActiveBurger.js

Source: DriverActiveBurger.js Github

copy
1import React from 'react';
2import "./DriverActiveBurger.css";
3
4export default class DriverActiveBurger extends React.Component{
5
6    componentDidMount(){
7
8    }
9
10    toggleDriverActiveMenu = ()=>{
11        const driverActivemenu = document.getElementById("driver-active-menu-container");
12
13        driverActivemenu.classList.toggle("open-driver-active-menu");
14    }
15
16
17    render(){
18        return (
19            <button id="driver-active-burger-container" onClick={this.toggleDriverActiveMenu}>
20                <div className="driver-active-burger-line-1"></div>
21                <div className="driver-active-burger-line-2"></div>
22                <div className="driver-active-burger-line-3"></div>
23            </button>
24        );
25    };
26};
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)