Skip to content

Commit 4b1f451

Browse files
fix: Add support to get elementRect (#134)
* Add support to get elementRect Co-authored-by: SrinivasanTarget <[email protected]> * Fix linting Co-authored-by: SrinivasanTarget <[email protected]> * Fix liniting error Co-authored-by: SrinivasanTarget <[email protected]> * Install appium 2.x Co-authored-by: SrinivasanTarget <[email protected]> --------- Co-authored-by: SrinivasanTarget <[email protected]>
1 parent ca96400 commit 4b1f451

File tree

9 files changed

+66
-7
lines changed

9 files changed

+66
-7
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
echo 'export UDID=$target_sim_id' >> $BASH_ENV
4747
xcrun simctl boot $target_sim_id
4848
xcrun simctl bootstatus $target_sim_id -b
49-
npm install -g appium
49+
npm install -g appium@2.19.0
5050
npm ci
5151
npm run build
5252
appium driver run xcuitest build-wda
@@ -97,7 +97,7 @@ jobs:
9797
echo 'export UDID=$target_sim_id' >> $BASH_ENV
9898
xcrun simctl boot $target_sim_id
9999
xcrun simctl bootstatus $target_sim_id -b
100-
npm install -g appium
100+
npm install -g appium@2.19.0
101101
npm ci
102102
npm run build
103103
appium driver run xcuitest build-wda

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
npm run build
4949
- name: Install Drivers
5050
run: |
51-
npm install -g appium
51+
npm install -g appium@2.19.0
5252
appium driver list
5353
- name: Checkout Test from Flutter Finder
5454
uses: actions/checkout@v2
@@ -125,7 +125,7 @@ jobs:
125125
npm run build
126126
- name: Install Drivers
127127
run: |
128-
npm install -g appium
128+
npm install -g appium@2.19.0
129129
appium driver list
130130
- name: Checkout Test from Flutter Finder
131131
uses: actions/checkout@v2

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/element.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ export async function getText(this: AppiumFlutterDriver, elementId: string) {
5656
return String(await driver.command(`/element/${elementId}/text`, 'GET', {}));
5757
}
5858

59+
export async function getElementRect(
60+
this: AppiumFlutterDriver,
61+
elementId: string,
62+
) {
63+
const driver = ELEMENT_CACHE.get(elementId);
64+
return await driver.command(`/element/${elementId}/rect`, 'GET', {});
65+
}
66+
5967
export async function elementEnabled(
6068
this: AppiumFlutterDriver,
6169
elementId: string,

src/driver.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
setValue,
2222
clear,
2323
ELEMENT_CACHE,
24+
getElementRect,
2425
} from './commands/element';
2526
import {
2627
attachAppLaunchArguments,
@@ -65,6 +66,7 @@ export class AppiumFlutterDriver extends BaseDriver<FlutterDriverConstraints> {
6566
findElOrEls = findElOrEls;
6667
getText = getText;
6768
getAttribute = getAttribute;
69+
getElementRect = getElementRect;
6870
elementDisplayed = elementDisplayed;
6971
elementEnabled = elementEnabled;
7072
setValue = setValue;
@@ -217,6 +219,10 @@ export class AppiumFlutterDriver extends BaseDriver<FlutterDriverConstraints> {
217219
isFlutterDriverCommand(command)
218220
) {
219221
return await super.executeCommand(command, ...args);
222+
} else {
223+
this.log.info(
224+
`Executing the command: ${command} with args: ${args} and flutterCommand ${isFlutterDriverCommand(command)}`,
225+
);
220226
}
221227

222228
this.handleContextSwitch(command, args);

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export function isFlutterDriverCommand(command: string) {
6161
'getAttribute',
6262
'elementDisplayed',
6363
'execute',
64+
'getElementRect',
65+
'getSize',
6466
].indexOf(command) >= 0
6567
);
6668
}

test/specs/test.e2e.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ describe('My Login application', () => {
6767
.flutterByValueKey$('double_tap_button')
6868
.flutterByText$('Double Tap');
6969
expect(await element.getText()).toEqual('Double Tap');
70+
const size = await element.getSize();
71+
expect(size.width).toBeGreaterThan(0);
72+
expect(size.height).toBeGreaterThan(0);
7073
await browser.flutterDoubleClick({
7174
element: element,
7275
});
@@ -101,6 +104,19 @@ describe('My Login application', () => {
101104
expect(await message.getText()).toEqual('Hello world');
102105
});
103106

107+
it.only('Nested Scroll Test', async () => {
108+
await performLogin();
109+
await openScreen('Nested Scroll');
110+
const parentElement = await browser.flutterScrollTillVisible({
111+
finder: await browser.flutterByText('Parent Element 4'),
112+
scrollDirection: 'down',
113+
});
114+
await browser.flutterScrollTillVisible({
115+
finder: await parentElement.flutterByValueKey(''),
116+
scrollView: parentElement,
117+
scrollDirection: 'down',
118+
});
119+
});
104120
it('Scroll Test', async () => {
105121
await performLogin();
106122
await openScreen('Vertical Swiping');

test/unit/element.specs.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
elementEnabled,
1212
findElOrEls,
1313
getAttribute,
14+
getElementRect,
1415
getText,
1516
setValue,
1617
} from '../../src/commands/element';
@@ -186,6 +187,32 @@ describe('Element Interaction Functions', () => {
186187
});
187188
});
188189

190+
describe('getRect', () => {
191+
it('should get rect from an element correctly', async () => {
192+
const elementId = 'elem1';
193+
ELEMENT_CACHE.set(elementId, mockDriver);
194+
mockDriver.command.resolves(
195+
'{"x": 10, "y": 20, "width": 100, "height": 50}',
196+
);
197+
198+
const result = await getElementRect.call(
199+
mockAppiumFlutterDriver,
200+
elementId,
201+
);
202+
203+
expect(result).to.equal(
204+
'{"x": 10, "y": 20, "width": 100, "height": 50}',
205+
);
206+
expect(
207+
mockDriver.command.calledWith(
208+
`/element/${elementId}/rect`,
209+
'GET',
210+
{},
211+
),
212+
).to.be.true;
213+
});
214+
});
215+
189216
describe('getAttribute', () => {
190217
it('should get an attribute from an element correctly', async () => {
191218
const elementId = 'elem1';

wdio.conf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const config: Options.Testrunner = {
142142

143143
//
144144
// The number of times to retry the entire specfile when it fails as a whole
145-
specFileRetries: 1,
145+
specFileRetries: 0,
146146
//
147147
// Delay in seconds between the spec file retry attempts
148148
// specFileRetriesDelay: 0,

0 commit comments

Comments
 (0)