Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for generating android matchers #425

Merged
merged 2 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions detox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@
"Emulator.js",
"DeviceDriverBase.js",
"GREYConfiguration.js",
"src/ios/earlgreyapi",
"src/utils/environment.js",
"AAPT.js",
"ADB.js",
"fsext.js"
"fsext.js",
"src/ios/earlgreyapi",
"src/android/espressoapi"
],
"resetMocks": true,
"resetModules": true,
Expand Down
142 changes: 142 additions & 0 deletions detox/src/android/espressoapi/DetoxAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated, probably needs to be removed in the generation code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a seperate PR. The generation is currently "dump" and nothing keeps track if these functions are needed or not. It might be a little more complex and unrelated to this set of changes to remove these in the generation. But it's one of my next ups on the list

This code is generated.
For more information see generation/README.md.
*/


// Globally declared helpers

function sanitize_greyDirection(action) {
switch (action) {
case "left":
return 1;
case "right":
return 2;
case "up":
return 3;
case "down":
return 4;

default:
throw new Error(`GREYAction.GREYDirection must be a 'left'/'right'/'up'/'down', got ${action}`);
}
}

function sanitize_greyContentEdge(action) {
switch (action) {
case "left":
return 0;
case "right":
return 1;
case "top":
return 2;
case "bottom":
return 3;

default:
throw new Error(`GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}`);
}
}

function sanitize_uiAccessibilityTraits(value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same applies here

let traits = 0;
for (let i = 0; i < value.length; i++) {
switch (value[i]) {
case 'button': traits |= 1; break;
case 'link': traits |= 2; break;
case 'header': traits |= 4; break;
case 'search': traits |= 8; break;
case 'image': traits |= 16; break;
case 'selected': traits |= 32; break;
case 'plays': traits |= 64; break;
case 'key': traits |= 128; break;
case 'text': traits |= 256; break;
case 'summary': traits |= 512; break;
case 'disabled': traits |= 1024; break;
case 'frequentUpdates': traits |= 2048; break;
case 'startsMedia': traits |= 4096; break;
case 'adjustable': traits |= 8192; break;
case 'allowsDirectInteraction': traits |= 16384; break;
case 'pageTurn': traits |= 32768; break;
default: throw new Error(`Unknown trait '${value[i]}', see list in https://facebook.github.io/react-native/docs/accessibility.html#accessibilitytraits-ios`);
}
}

return traits;
}



class DetoxAction {
static multiClick(times) {
if (typeof times !== "number") throw new Error("times should be a number, but got " + (times + (" (" + (typeof times + ")"))));
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.DetoxAction"
},
method: "multiClick",
args: [{
type: "Integer",
value: times
}]
};
}

static tapAtLocation(x, y) {
if (typeof x !== "number") throw new Error("x should be a number, but got " + (x + (" (" + (typeof x + ")"))));
if (typeof y !== "number") throw new Error("y should be a number, but got " + (y + (" (" + (typeof y + ")"))));
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.DetoxAction"
},
method: "tapAtLocation",
args: [{
type: "Integer",
value: x
}, {
type: "Integer",
value: y
}]
};
}

static scrollToEdge(edge) {
if (typeof edge !== "number") throw new Error("edge should be a number, but got " + (edge + (" (" + (typeof edge + ")"))));
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.DetoxAction"
},
method: "scrollToEdge",
args: [{
type: "Integer",
value: edge
}]
};
}

static scrollInDirection(direction, amountInDP) {
if (typeof direction !== "number") throw new Error("direction should be a number, but got " + (direction + (" (" + (typeof direction + ")"))));
if (typeof amountInDP !== "number") throw new Error("amountInDP should be a number, but got " + (amountInDP + (" (" + (typeof amountInDP + ")"))));
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.DetoxAction"
},
method: "scrollInDirection",
args: [{
type: "Integer",
value: direction
}, {
type: "double",
value: amountInDP
}]
};
}

}

module.exports = DetoxAction;
3 changes: 2 additions & 1 deletion detox/src/android/expect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const invoke = require('../invoke');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want to add the other actions as well ?
Did you run the Android E2E suite with the new implementation ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the e2e suite with the old implementation, will re-run it the next days with the newer one. As I said, I would like to add the actions step by step to have smaller, easier to merge PRs.

const matchers = require('./matcher');
const DetoxActionApi = require('./espressoapi/DetoxAction');
const Matcher = matchers.Matcher;
const LabelMatcher = matchers.LabelMatcher;
const IdMatcher = matchers.IdMatcher;
Expand Down Expand Up @@ -51,7 +52,7 @@ class LongPressAction extends Action {
class MultiClickAction extends Action {
constructor(times) {
super();
this._call = invoke.call(invoke.Android.Class(DetoxAction), 'multiClick', invoke.Android.Integer(times));
this._call = invoke.callDirectly(DetoxActionApi.multiClick(times));
}
}

Expand Down
4 changes: 2 additions & 2 deletions detox/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"test": ":",
"packager": "react-native start",
"detox-server": "detox run-server",
"e2e:ios": "detox test --configuration ios.sim.release --debug-synchronization 10000",
"e2e:android": "detox test --configuration android.emu.release --loglevel verbose",
"e2e:ios": "detox test --configuration ios.sim.release --debug-synchronization 10000 --platform ios",
"e2e:android": "detox test --configuration android.emu.release --loglevel verbose --platform android",
"build:ios": "detox build --configuration ios.sim.release",
"build:android": "detox build --configuration android.emu.release"
},
Expand Down
19 changes: 19 additions & 0 deletions generation/__tests__/__snapshots__/android.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Android generation methods should generate type checks 1`] = `"times should be a number, but got FOO (string)"`;

exports[`Android generation methods should return adapter calls 1`] = `
Object {
"args": Array [
Object {
"type": "Integer",
"value": 3,
},
],
"method": "multiClick",
"target": Object {
"type": "Class",
"value": "com.wix.detox.espresso.DetoxAction",
},
}
`;
100 changes: 0 additions & 100 deletions generation/__tests__/__snapshots__/earl-grey.js.snap

This file was deleted.

Loading