-
Notifications
You must be signed in to change notification settings - Fork 58
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 Paste UI Tests for Android #1100
Changes from 7 commits
893bdb7
1bb6db5
606686b
de90246
546d09e
2851edb
5c04b37
4875cc4
11656c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/** | ||
* @format | ||
* */ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import EditorPage from './pages/editor-page'; | ||
import { | ||
setupDriver, | ||
isLocalEnvironment, | ||
longPressMiddleOfElement, | ||
tapSelectAllAboveElement, | ||
tapCopyAboveElement, | ||
tapPasteAboveElement, | ||
stopDriver, | ||
isAndroid, | ||
} from './helpers/utils'; | ||
import testData from './helpers/test-data'; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 240000; | ||
|
||
describe( 'Gutenberg Editor paste tests', () => { | ||
// skip iOS for now | ||
if ( ! isAndroid() ) { | ||
it( 'skips the tests on any platform other than Android', async () => { | ||
} ); | ||
return; | ||
} | ||
|
||
let driver; | ||
let editorPage; | ||
let allPassed = true; | ||
|
||
// Use reporter for setting status for saucelabs Job | ||
if ( ! isLocalEnvironment() ) { | ||
const reporter = { | ||
specDone: async ( result ) => { | ||
allPassed = allPassed && result.status !== 'failed'; | ||
}, | ||
}; | ||
|
||
jasmine.getEnv().addReporter( reporter ); | ||
} | ||
|
||
beforeAll( async () => { | ||
driver = await setupDriver(); | ||
await driver.setClipboard( '', 'plaintext' ); | ||
editorPage = new EditorPage( driver ); | ||
} ); | ||
|
||
it( 'copies plain text from one paragraph block and pastes in another', async () => { | ||
await editorPage.addNewParagraphBlock(); | ||
const paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 1 ); | ||
|
||
if ( isAndroid() ) { | ||
await paragraphBlockElement.click(); | ||
} | ||
|
||
await editorPage.sendTextToParagraphBlock( paragraphBlockElement, testData.pastePlainText ); | ||
const textViewElement = await editorPage.getTextViewForParagraphBlock( paragraphBlockElement ); | ||
|
||
// copy content to clipboard | ||
await longPressMiddleOfElement( driver, textViewElement ); | ||
await tapSelectAllAboveElement( driver, textViewElement ); | ||
await tapCopyAboveElement( driver, textViewElement ); | ||
|
||
// create another paragraph block | ||
await editorPage.addNewParagraphBlock(); | ||
const paragraphBlockElement2 = await editorPage.getParagraphBlockAtPosition( 2 ); | ||
|
||
if ( isAndroid() ) { | ||
await paragraphBlockElement2.click(); | ||
} | ||
|
||
const textViewElement2 = await editorPage.getTextViewForParagraphBlock( paragraphBlockElement2 ); | ||
|
||
// paste into second paragraph block | ||
await longPressMiddleOfElement( driver, textViewElement2 ); | ||
await tapPasteAboveElement( driver, textViewElement2 ); | ||
|
||
const text = await editorPage.getTextForParagraphBlockAtPosition( 2 ); | ||
expect( text ).toBe( testData.pastePlainText ); | ||
} ); | ||
|
||
it( 'copies styled text from one paragraph block and pastes in another', async () => { | ||
// create paragraph block with styled text by editing html | ||
await editorPage.setHtmlContentAndroid( testData.pasteHtmlText ); | ||
const paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 1 ); | ||
|
||
if ( isAndroid() ) { | ||
await paragraphBlockElement.click(); | ||
} | ||
|
||
const textViewElement = await editorPage.getTextViewForParagraphBlock( paragraphBlockElement ); | ||
|
||
// copy content to clipboard | ||
await longPressMiddleOfElement( driver, textViewElement ); | ||
await tapSelectAllAboveElement( driver, textViewElement ); | ||
await tapCopyAboveElement( driver, textViewElement ); | ||
|
||
// create another paragraph block | ||
await editorPage.addNewParagraphBlock(); | ||
const paragraphBlockElement2 = await editorPage.getParagraphBlockAtPosition( 2 ); | ||
|
||
if ( isAndroid() ) { | ||
await paragraphBlockElement2.click(); | ||
} | ||
|
||
const textViewElement2 = await editorPage.getTextViewForParagraphBlock( paragraphBlockElement2 ); | ||
|
||
// paste into second paragraph block | ||
await longPressMiddleOfElement( driver, textViewElement2 ); | ||
await tapPasteAboveElement( driver, textViewElement2 ); | ||
|
||
// check styled text by verifying html contents | ||
await editorPage.verifyHtmlContent( testData.pasteHtmlTextResult ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
if ( ! isLocalEnvironment() ) { | ||
driver.sauceJobStatus( allPassed ); | ||
} | ||
await stopDriver( driver ); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,54 @@ const clickBeginningOfElement = async ( driver: wd.PromiseChainWebdriver, elemen | |
await action.perform(); | ||
}; | ||
|
||
// long press to activate context menu | ||
const longPressMiddleOfElement = async ( driver: wd.PromiseChainWebdriver, element: wd.PromiseChainWebdriver.Element ) => { | ||
const location = await element.getLocation(); | ||
const size = await element.getSize(); | ||
|
||
const action = await new wd.TouchAction( driver ); | ||
const x = location.x + ( size.width / 2 ); | ||
const y = location.y + ( size.height / 2 ); | ||
action.press( { x, y } ); | ||
action.wait( 2000 ); | ||
action.release(); | ||
await action.perform(); | ||
}; | ||
|
||
// press "Select All" in floating context menu | ||
const tapSelectAllAboveElement = async ( driver: wd.PromiseChainWebdriver, element: wd.PromiseChainWebdriver.Element ) => { | ||
const location = await element.getLocation(); | ||
const action = await new wd.TouchAction( driver ); | ||
const x = location.x + 300; | ||
const y = location.y - 50; | ||
action.press( { x, y } ); | ||
//action.wait( 1000 ); | ||
action.release(); | ||
await action.perform(); | ||
}; | ||
|
||
// press "Copy" in floating context menu | ||
const tapCopyAboveElement = async ( driver: wd.PromiseChainWebdriver, element: wd.PromiseChainWebdriver.Element ) => { | ||
const location = await element.getLocation(); | ||
const action = await new wd.TouchAction( driver ); | ||
const x = location.x + 220; | ||
const y = location.y - 50; | ||
action.press( { x, y } ); | ||
//action.wait( 1000 ); | ||
action.release(); | ||
await action.perform(); | ||
}; | ||
|
||
// press "Paste" in floating context menu | ||
const tapPasteAboveElement = async ( driver: wd.PromiseChainWebdriver, element: wd.PromiseChainWebdriver.Element ) => { | ||
const location = await element.getLocation(); | ||
const action = await new wd.TouchAction( driver ); | ||
action.press( { x: location.x + 100, y: location.y - 50 } ); | ||
//action.wait( 1000 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will remove this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I've removed them. |
||
action.release(); | ||
await action.perform(); | ||
}; | ||
|
||
// Starts from the middle of the screen or the element(if specified) | ||
// and swipes upwards | ||
const swipeUp = async ( driver: wd.PromiseChainWebdriver, element: wd.PromiseChainWebdriver.Element = undefined ) => { | ||
|
@@ -241,6 +289,10 @@ module.exports = { | |
typeString, | ||
clickMiddleOfElement, | ||
clickBeginningOfElement, | ||
longPressMiddleOfElement, | ||
tapSelectAllAboveElement, | ||
tapCopyAboveElement, | ||
tapPasteAboveElement, | ||
swipeUp, | ||
stopDriver, | ||
toggleHtmlMode, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably remove this right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll push a commit to remove those. Initially, I wasn't sure if they were required, as I'd seen similar waits on examples online.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've removed them.