public class MobileCommonMethods extends Object
Modifier and Type | Field and Description |
---|---|
static io.appium.java_client.AppiumDriver |
driver
The driver.
|
static int |
sleepTimeAverage
The sleep time average.
|
static int |
sleepTimeAverage2
The sleep time average2.
|
static int |
sleepTimeMax
The sleep time max.
|
static int |
sleepTimeMax2
The sleep time max2.
|
static int |
sleepTimeMin
The sleep time min.
|
static int |
sleepTimeMin2
The sleep time min2.
|
Constructor and Description |
---|
MobileCommonMethods() |
Modifier and Type | Method and Description |
---|---|
static void |
callingImplicitSleep()
Webdriver implicit sleep.
|
static void |
clearField(org.openqa.selenium.By by)
Clear field content.
|
static void |
clickElementAtIndex(org.openqa.selenium.By byElementLocator,
int index)
Select an element at specific index and clicks on it.
|
static void |
clickElementsPresentWithSameLocatorAtDiffIndex(org.openqa.selenium.By elementLocator,
org.openqa.selenium.By expectedPageTitleLocator,
org.openqa.selenium.By basePageUniqueElementLocator)
Elements at different index with same locator is clicked to check what exactly it opens.
|
static int |
countElementsPresentWithSameLocator(org.openqa.selenium.WebDriver driver,
org.openqa.selenium.By by)
Checks if element is present in current screen of mobile device for the locator passed.
|
static org.openqa.selenium.Point |
getCenter(org.openqa.selenium.By byElementLocator)
Gets the center.
|
static List<org.openqa.selenium.WebElement> |
getElementsPresentForSameLocator(org.openqa.selenium.WebDriver driver,
org.openqa.selenium.By by)
Gets all the elements present for the locator passed.
|
static void |
initializeSleepTimings()
Initialize all sleep timings variables.
|
static Boolean |
isElementDisplayed(org.openqa.selenium.By byElementLocator)
Checks if element is displayed or not.
|
static boolean |
isElementPresent(org.openqa.selenium.WebDriver driver,
org.openqa.selenium.By by)
Checks if element is present on the current screen.
|
static void |
launchEmulatorAndroidApp(String appName)
Launch emulator android app.
|
static void |
launchEmulatorAndroidAppViaLocalAPKPath(String localSysApkPath)
Launch emulator and installs android app via local system APK path and then launches the App directly.
|
static void |
launchEmulatorAndroidBrowser()
Launch emulator android browser.
|
static void |
launchRealAndroidApp(String appName)
Launch app based on appName.
|
static void |
navigateBack()
Navigate back: Navigates to previous page.
|
static void |
quitApp(org.testng.ITestResult result)
Quits app + driver + takes screenshot of the page where failure occurred(if any).
Screenshot is saved @..projectRootDirectory/failure_screenshots/ |
static void |
screenshotMobile(String methodName)
Screenshot mobile.
Stored within "failure_Screenshot" folder with File name format: methodName_dd_MM_yyyy_hh_mm_ss.png Ex: loginCheck_28_10_2015_07_10_10.png |
static void |
scrollFindAndClickOnElement(org.openqa.selenium.By byElementLocator,
int repeatSwipe)
Find and click on element.
|
static void |
scrollToAndClickOnElement(String elementName)
Scroll to and click on element.
|
static void |
sendKeyEvent(String keyEvent)
Customized Appium Send key event
Pass the exact parameter name which exists in config.properties file within "Android Key Event properties" section |
static void |
swipe(double xStart,
double yStart,
double xEnd,
double yEnd,
int swipeTime,
int totalSwipes)
Custom Swipe method for Appium.
|
static void |
swipeDown(int swipeTimeInMilliSecs,
int swipeRepeat)
Swipe down.
|
static void |
swipeUp(int swipeTimeInMilliSecs,
int swipeRepeat)
Swipe up.
|
static void |
waitForElementToBeClickable(org.openqa.selenium.By by,
int seconds)
Waits for desired Seconds for the element to be Clickable.
|
static void |
waitForElementToBeSelected(org.openqa.selenium.By by,
int seconds)
Waits for desired Seconds and then checks for the element to be Selected.
|
static void |
waitingForTheElementToLoad(org.openqa.selenium.By by,
int seconds)
Waits for desired seconds and then checks if the element is visible or not.
|
static void |
waitSeconds(int seconds)
Wait seconds.
|
public static io.appium.java_client.AppiumDriver driver
public static int sleepTimeMin
public static int sleepTimeMin2
public static int sleepTimeAverage
public static int sleepTimeAverage2
public static int sleepTimeMax
public static int sleepTimeMax2
public static void launchRealAndroidApp(String appName) throws Exception
appName
- the app name. Ex:"flipkart" or"fk" or anything which is exactly same as variable name in config.properties fileException
- the exceptionpublic static void launchEmulatorAndroidAppViaLocalAPKPath(String localSysApkPath) throws Exception
localSysApkPath
- the local sys apk path.Exception
- the exceptionpublic static void launchEmulatorAndroidApp(String appName) throws Exception
appName
- the app name. Ex:"flipkart" or"fk" or anything which is exactly same as variable name in config.properties fileException
- the exceptionpublic static void launchEmulatorAndroidBrowser() throws Exception
Exception
- the exceptionpublic static void screenshotMobile(String methodName) throws Exception
methodName
- the method nameException
- the exceptionpublic static void waitSeconds(int seconds) throws Exception
seconds
- the secondsException
- the exceptionpublic static void waitingForTheElementToLoad(org.openqa.selenium.By by, int seconds) throws Exception
by
- Pass the element as By.xpath / By.Id / By.Name or any other locator type supported with ByException
- the exceptionpublic static void waitForElementToBeSelected(org.openqa.selenium.By by, int seconds) throws Exception
by
- Pass the element as By.xpath / By.Id / By.Name or any other locator type supported with ByException
- the exceptionpublic static void waitForElementToBeClickable(org.openqa.selenium.By by, int seconds) throws Exception
by
- Pass the element as By.xpath / By.Id / By.Name or any other locator type supported with ByException
- the exceptionpublic static void callingImplicitSleep() throws Exception
Exception
- the exceptionpublic static void initializeSleepTimings() throws IOException, Exception
IOException
- Signals that an I/O exception has occurred.Exception
public static boolean isElementPresent(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By by) throws Exception
driver
- the driverby
- Pass the element as By.xpath / By.Id / By.Name or any other locator type supported with ByException
- the exceptionpublic static Boolean isElementDisplayed(org.openqa.selenium.By byElementLocator)
byElementLocator
- the by element locatorpublic static int countElementsPresentWithSameLocator(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By by) throws Exception
driver
- the driverby
- Pass the element as By.xpath / By.Id / By.Name or any other locator type supported with ByException
- the exceptionpublic static List<org.openqa.selenium.WebElement> getElementsPresentForSameLocator(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By by) throws Exception
driver
- the driverby
- Pass the element as By.xpath / By.Id / By.Name or any other locator type supported with ByException
public static void clickElementsPresentWithSameLocatorAtDiffIndex(org.openqa.selenium.By elementLocator, org.openqa.selenium.By expectedPageTitleLocator, org.openqa.selenium.By basePageUniqueElementLocator) throws Exception
elementLocator
- the element locator which is ambiguous on BasePageexpectedPageTitleLocator
- the expected BasePage title locator. Checks if control is still on same BasePage after clicking.basePageUniqueElementLocator
- the base page unique element locator for assert purpose. Ex:'By.name(hamburgerName)'Exception
- the exceptionpublic static void clickElementAtIndex(org.openqa.selenium.By byElementLocator, int index) throws Exception
byElementLocator
- the by element locator."By.className(String className)"index
- the indexException
- the exceptionpublic static void clearField(org.openqa.selenium.By by) throws Exception
by
- the by. Ex: "By.className(String className)"Exception
public static void sendKeyEvent(String keyEvent) throws Exception
keyEvent
- the key event. Ex: "backspaceKeyEvent" variable which exists in config.properties fileException
public static void navigateBack() throws Exception
Exception
- the exceptionpublic static org.openqa.selenium.Point getCenter(org.openqa.selenium.By byElementLocator) throws Exception
byElementLocator
- the by element locator. Ex: "By.className(String className)"Exception
- the exceptionpublic static void swipe(double xStart, double yStart, double xEnd, double yEnd, int swipeTime, int totalSwipes) throws IOException, Exception
xStart
- the x start coordinatesyStart
- the y start coordinatesxEnd
- the x end coordinatesyEnd
- the y end coordinatesswipeTime
- the sweep timetotalSwipes
- the total swipesIOException
- Signals that an I/O exception has occurred.Exception
- the exceptionpublic static void swipeUp(int swipeTimeInMilliSecs, int swipeRepeat) throws InterruptedException
swipeTimeInMilliSecs
- the swipe time in milli secsswipeRepeat
- the number of times 'swipe up' repeatInterruptedException
- the interrupted exceptionpublic static void swipeDown(int swipeTimeInMilliSecs, int swipeRepeat) throws InterruptedException
swipeTimeInMilliSecs
- the swipe time in milli secsswipeRepeat
- the number of times 'swipe down' repeatsInterruptedException
- the interrupted exceptionpublic static void scrollToAndClickOnElement(String elementName) throws Exception
elementName
- the element nameException
- the exceptionpublic static void scrollFindAndClickOnElement(org.openqa.selenium.By byElementLocator, int repeatSwipe) throws Exception
byElementLocator
- the by element locator. Ex: "By.className(String className)"repeatSwipe
- Total swipe to be done. Tries to find an element after Swipe is done each time.Exception
- the exceptionpublic static void quitApp(org.testng.ITestResult result) throws Exception
result
- the result. Ex: "ITestResult result". This needs TestNG Jar to work.Exception