How to use setPreferences 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
_

Settings.js

Source: Settings.js Github

copy
1import React from "react";
2import Modal from "@mui/material/Modal";
3import Switch from "@mui/material/Switch";
4import { styled } from "@mui/material/styles";
5
6import "./settings.css";
7
8const style = {
9  position: "absolute",
10  top: "50%",
11  left: "50%",
12  transform: "translate(-50%, -50%)",
13  width: "350px",
14  backgroundColor: "#334756",
15  borderRadius: "10px",
16  outline: "none",
17  boxShadow: 24,
18  p: 4,
19};
20
21const CustomSwitch = styled(Switch)(() => ({
22  "& .MuiSwitch-switchBase.Mui-checked": {
23    color: "#5C7AEA",
24  },
25  "& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track": {
26    backgroundColor: "#5C7AEA",
27  },
28}));
29
30const Settings = ({ openModal, setOpenModal, preferences, setPreferences }) => {
31  return (
32    <div>
33      <Modal
34        open={openModal}
35        onClose={() => setOpenModal(false)}
36        aria-labelledby="modal-modal-title"
37        aria-describedby="modal-modal-description"
38      >
39        <div className="modal-wrapper" style={style}>
40          <div className="option">
41            <p>Font Size</p>
42            <div className="dropdown">
43              <p>{preferences.fontSize}px</p>
44              <div className="dropdown-content">
45                <p
46                  onClick={() =>
47                    setPreferences((prevState) => ({
48                      ...prevState,
49                      fontSize: "12",
50                    }))
51                  }
52                >
53                  12px
54                </p>
55                <p
56                  onClick={() =>
57                    setPreferences((prevState) => ({
58                      ...prevState,
59                      fontSize: "14",
60                    }))
61                  }
62                >
63                  14px
64                </p>
65                <p
66                  onClick={() =>
67                    setPreferences((prevState) => ({
68                      ...prevState,
69                      fontSize: "16",
70                    }))
71                  }
72                >
73                  16px
74                </p>
75                <p
76                  onClick={() =>
77                    setPreferences((prevState) => ({
78                      ...prevState,
79                      fontSize: "18",
80                    }))
81                  }
82                >
83                  18px
84                </p>
85              </div>
86            </div>
87          </div>
88          <div className="option">
89            <p>Theme</p>
90            <div className="dropdown">
91              <p>{preferences.theme}</p>
92              <div className="dropdown-content">
93                <p
94                  onClick={() =>
95                    setPreferences((prevState) => ({
96                      ...prevState,
97                      theme: "night",
98                    }))
99                  }
100                >
101                  night
102                </p>
103                <p
104                  onClick={() =>
105                    setPreferences((prevState) => ({
106                      ...prevState,
107                      theme: "material",
108                    }))
109                  }
110                >
111                  material
112                </p>
113                <p
114                  onClick={() =>
115                    setPreferences((prevState) => ({
116                      ...prevState,
117                      theme: "monokai",
118                    }))
119                  }
120                >
121                  monokai
122                </p>
123                <p
124                  onClick={() =>
125                    setPreferences((prevState) => ({
126                      ...prevState,
127                      theme: "default",
128                    }))
129                  }
130                >
131                  default (light)
132                </p>
133              </div>
134            </div>
135          </div>
136          <div className="option">
137            <p>Line Numbering</p>
138            <div className="lineNumbers-div">
139              <CustomSwitch
140                checked={preferences.lineNumbers}
141                onChange={(e) =>
142                  setPreferences((prevState) => ({
143                    ...prevState,
144                    lineNumbers: e.target.checked,
145                  }))
146                }
147                inputProps={{ "aria-label": "controlled" }}
148              />
149            </div>
150          </div>
151        </div>
152      </Modal>
153    </div>
154  );
155};
156
157export default Settings;
158
Full Screen

localstorage.js

Source: localstorage.js Github

copy
1module("core.localstorage");
2
3test('用 UE.LocalStorage 对字符串做保存/读取/删除操作', function () {
4
5    var str = '[email protected]#$%^&*()_+qwertyuiopasdfghjklzxcvbnm,./<>?;\':"[]\\{}|';
6    UE.LocalStorage.saveLocalData('test_string1', str);
7    equal(UE.LocalStorage.getLocalData('test_string1'), str, "保存内容,并读取内容");
8
9    UE.LocalStorage.saveLocalData('test_string2', str);
10    UE.LocalStorage.removeItem('test_string2');
11    equal(UE.LocalStorage.getLocalData('test_string2'), undefined, "保存内容,并删除内容");
12
13});
14
15test('偏好设置相关方法setPreferencesue、getPreferences、removePreferences', function () {
16
17    var editor = te.obj[1];
18
19    var str = '[email protected]#$%^&*()_+qwertyuiopasdfghjklzxcvbnm,./<>?;\':"[]\\{}|';
20    editor.setPreferences('test_string', str);
21    equal(editor.getPreferences('test_string'), str, "保存字符串,并读取内容");
22
23    var obj = {
24        nul: null,
25        boo1: true,
26        boo2: false,
27        str: 'aaa',
28        arr: [1, '2', 'a'],
29        obj: {k1:1, k2:'2', k3:'a'}
30    };
31    editor.setPreferences('test_object', obj);
32    same(editor.getPreferences('test_object'), obj, "保存键值对象,并读取内容");
33
34    editor.setPreferences('test_boolean', true);
35    equal(editor.getPreferences('test_boolean'), true, "保存布尔值,并读取内容");
36
37    var arr = [1, '2', 'a'];
38    editor.setPreferences('test_string', arr);
39    same(editor.getPreferences('test_string'), arr, "保存数组,并读取内容");
40
41    var tmpStr = 'string_content';
42    editor.setPreferences('test_delete', tmpStr);
43    editor.removePreferences('test_delete');
44    equal(editor.getPreferences('test_delete'), undefined, "保存字符串,并删除内容");
45
46});
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)