Project is configured with log4j for debug logs. How to configure project with log4j property follow the link https://sachingainewar.blogspot.com/2019/11/log4j-implementation-to-generates-logs.html
http://sachingainewar.blogspot.com/2019/11/allure-report-system-configuration-with.html
src.test.java.test.FlipKart.CreateDriver.java
is an example for creating the private instance of driver with ThreadLocal class
src/test/java/test/FlipKart/AppiumServerJava.java is an example for appium configuration
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
Function " alertHandle() " - in Class "src/test/java/test/FlipKart/Select.java"
//handle automate React Native application & I want to click on Button which does not have any Resource ID and content-desc and button is clickable=‘False’
new TouchAction((MobileDriver) driver).press(618,1791).waitAction().moveTo(1059,1896).release().perform();
xpath=//android.view.ViewGroup//android.widget.ImageButton[@content-desc='Back Button']
``` FlipKartAppTest/src/test/java/test/FlipKart/LocatorType.java
//follow the formate of locators like "xpath=//*[@id='abc'], class="abc", id="asa",etc ". So first separate string by (=).
public By getLocator(String locator, LocatorType xpt) {
By by = null;
switch (xpt) {
case xpath:
by = MobileBy.xpath(locator);
break;
case classname:
by = MobileBy.className(locator);
break;
case id:
by = MobileBy.id(locator);
break;
default:
by = MobileBy.xpath(locator);
break;
}
return by;
}
// finally use the By class to get the element
By by = getMobileLocator(locator, identifier);
element = wait.until(ExpectedConditions.presenceOfElementLocated(by));
```
``` public static void swipe(MobileDriver driver, DIRECTION direction, long duration) {
Dimension size = driver.manage().window().getSize();
int startX = 0;
int endX = 0;
int startY = 0;
int endY = 0;
switch (direction) {
case RIGHT:
startY = (int) (size.height / 2);
startX = (int) (size.width * 0.90);
endX = (int) (size.width * 0.05);
new TouchAction(driver)
.press(startX, startY)
.waitAction(Duration.ofMillis(duration))
.moveTo(endX, startY)
.release()
.perform();
break;
case LEFT:
startY = (int) (size.height / 2);
startX = (int) (size.width * 0.05);
endX = (int) (size.width * 0.90);
new TouchAction(driver)
.press(startX, startY)
.waitAction(Duration.ofMillis(duration))
.moveTo(endX, startY)
.release()
.perform();
break;
case UP:
endY = (int) (size.height * 0.70);
startY = (int) (size.height * 0.30);
startX = (size.width / 2);
new TouchAction(driver)
.press(startX, startY)
.waitAction(Duration.ofMillis(duration))
.moveTo(endX, startY)
.release()
.perform();
break;
case DOWN:
startY = (int) (size.height * 0.70);
endY = (int) (size.height * 0.30);
startX = (size.width / 2);
new TouchAction(driver)
.press(startX, startY)
.waitAction(Duration.ofMillis(duration))
.moveTo(startX, endY)
.release()
.perform();
break;
}
} ```
NOTE: Just BrowserStack initialization code added but not configured, means cant directlty run code on browserstack
static Common getMethod = new Common();
public static RemoteWebDriver driver;
static Properties properties = new Properties();
static int count = 0;
public static final String USERNAME = "sachin510";
public static final String AUTOMATE_KEY = properties.getProperty("AuthKey");
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
static Delay delay = new Delay();
@BeforeTest
public void setConnectionToBroserStack() throws InterruptedException, ExecuteException, IOException {
// Initializing command line parameters...
CommandLine cmdLine = new CommandLine("cmd.exe");
cmdLine.addArgument(
"C:\\Users\\sgainewar>\\Documents\\new\\9-1-2018\\BrowserStackLocal.exe --key zKpP3Muz6StvsebgqUqm");
/*
* cmdLine.addArgument("--key");
* cmdLine.addArgument("zKpP3Muz6StvsebgqUqm");
*/
System.out.println(cmdLine);
DefaultExecutor executor = new DefaultExecutor();
int exitValue = executor.execute(cmdLine);
System.out.println(exitValue);
}
static Common getMethod = new Common();
public static RemoteWebDriver driver;
static Properties properties = new Properties();
static int count = 0;
public static final String USERNAME = "xxxxxxxx";
public static final String AUTOMATE_KEY = ("AuthKey");
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
static Delay delay = new Delay();
public void setConnectionToBroserStack() throws InterruptedException, ExecuteException, IOException {
// Initializing command line parameters...
CommandLine cmdLine = new CommandLine("cmd.exe");
cmdLine.addArgument(
"C:\\Users\\sgainewar>\\Documents\\new\\9-1-2018\\BrowserStackLocal.exe --key xxxxxxxxx");
/*
* cmdLine.addArgument("--key");
* cmdLine.addArgument("xxxxxxxxxxxx");
*/
System.out.println(cmdLine);
DefaultExecutor executor = new DefaultExecutor();
int exitValue = executor.execute(cmdLine);
System.out.println(exitValue);
}