Reputation: 33
I just trying copy / paste text from gmail to another input, and realized that the cafe test doesn't support ctrl-c, ctrl-v.
Here's what I tried to do:
pom:
import { Selector, t} from 'testcafe';
class LoginPage {
copyStepCarrierPassword: Selector;
copyCarrierPassword: Selector;
emailInput: Selector;
constructor(){
this.copyStepCarrierPassword = Selector('[class="ams bkG"]');
this.copyCarrierPassword = Selector('[class="gmail_quote"]');
this.emailInput = Selector('[id="userEmail"]');
}
async copyPassword(){
await t
.selectText(this.copyCarrierPassword, 1, 10)
.pressKey('ctrl+c');
}
async navigateToCarrierPage(carrierPageUrl){
await t
.navigateTo(carrierPageUrl)
}
async setEmailInput(emailInput){
await t
.typeText(this.emailInput, emailInput)
.pressKey('ctrl+v');
}
}
test:
test('Copy/Paste password',
async t => {
await t
LoginPage.copyStepPassword();
await t.wait(1000);
LoginPage.copyPassword();
await t.wait(3000);
await t.openWindow(carrierUrl);
LoginPage.setEmailInput('');
await t.wait(3000);
}
I saw example here, but I don't know how to use it in my case. Who knows how to resolve this problem?
Upvotes: 0
Views: 413
Reputation: 8332
I wonder what you test in this case anyway. That Ctrl+C and Ctrl+V work? But that has most likely nothing to do with your app. Why don't you just get the text and then input it into that user email input? Why do you have to do it with Ctrl+C and Ctrl+V?
If you really really need paste feature, there's an option for that in .typeText()
method:
await t
.typeText(this.emailInput, emailInput, { paste: true });
Since you copy from Gmail, I think you don't need to do it with Ctrk+C. I think you don't really need to use UI for that anyway. There're good reasons for that, one is that you have no control over Gmail app, so if they change the UI/selectors, your test will fail. That's flaky and you want to avoid that. Learn how to use API calls instead.
Upvotes: 3