appium-boilerplate
appium-boilerplate copied to clipboard
[Help] How can we swap from one page another
Hello we are planning to automated our application on mobile browsers and choose WebdriverIO as framework, which is new to us
suppose , I have a ebook, I want turn pages 1-2, 2-3 like but I see browser.swipeRight but while execution it says browser.swipeRight is not a function
is there any way to swipe pages , we have option several options to turn pages like when user swap or when user tap on the screen <left/right side of the page not in the middle>
can you help to handle this scenario?
Platform: Mobile chrome browser <Emulator and real device>
am attaching here few screens to understanding better way.
Swipe.ts
class Swipe {
async right() {
const cordinates = this.getScreenSize()
if (cordinates) {
const width = cordinates[0]
const height = cordinates[1]
await browser.touchAction([
{
action: 'press',
x: width * 0.9,
y: height / 2
},
{
action: 'wait',
ms: 800
},
{
action: 'moveTo',
x: width * 0.1, y: height / 2
},
{
action: 'release'
}
])
}
}
async left() {
const cordinates = this.getScreenSize()
if (cordinates) {
const width = cordinates[0]
const height = cordinates[1]
await browser.touchAction([
{
action: 'press',
x: width * 0.1,
y: height / 2
},
{
action: 'wait',
ms: 800
},
{
action: 'moveTo',
x: width * 0.9, y: height / 2
},
{
action: 'release'
}
])
}
}
async getScreenSize() {
let width = 0
let height = 0
const cordinates=[];
const windowSize = await browser.getWindowSize();
console.log(windowSize);
width = windowSize.width;
height = windowSize.height;
console.log("width:" + width)
console.log("height:" + height)
return cordinates.push(width,height)
}
}
module.exports = new Swipe();
created a class for swipe but it failing to load the fail , yes, browser.touchAction in here browser showing some error..do I need to import any package to solve this issues?
Hi @MonoAutomation
Thanks for the request. What type of error are you getting? Secondly, your class has an error, this const cordinates = this.getScreenSize()
should be await const cordinates = this.getScreenSize()
to make this work.
There are also some sync (will add async examples in the coming weeks) in this boilerplate. Just remember that there are no default swipe methods in WDIO/Appium that will work cross platform. You need to build your own, especially because every app / screen might behave different.
By the way, I'm giving a talk about this during Appium Conf, see https://confengine.com/conferences/appium-conf-2021/proposal/15544/swiping-your-way-through-appium.
thank you sir for your response and solution.
I could able to swipe with touch actions
but I have a issue with swipe.ts file where I have created swipe method ,as per your comment added await
the issue is:
Unable to load spec files quite likely because they rely on browser
object that is not fully initialised.
[0-0] browser
object has only capabilities
and some flags like isMobile
.
[0-0] Helper files that use other browser
commands have to be moved to before
hook.
Error: Error: Cannot find module '../helpers/Swipe
as I ware that browser pr driver is global object but here in this class why browser or driver object showing some error ?
am I missing anything here?
am I missing anything here?
Don't call any commands outside of it
blocks or hooks.
Let me know if you have further questions, thanks for reporting!