Skip to content
Open
2 changes: 1 addition & 1 deletion TestNG/webTestng.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Web Automation Tests" preserve-order="true" configfailurepolicy="continue" parallel="methods" thread-count="1">
<suite name="Web Automation Tests" preserve-order="true" configfailurepolicy="continue" parallel="methods" thread-count="4">
<test name="LoginTests" preserve-order="true">
<classes>
<class name="com.znsio.rpap.WebExampleTest"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<dependency>
<groupId>com.github.znsio</groupId>
<artifactId>ApplitoolsIntegration</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the applitools latest PR is merged - update this version

<version>5e507fbf56</version>
<version>6b17819</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/znsio/rpap/pages/BasePage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.znsio.rpap.pages;

import com.znsio.rpap.utils.DriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
Expand All @@ -18,7 +19,7 @@ public BasePage(WebDriver driver, WebDriverWait wait) {
//TODO: Simplify this method. Avoid the usage of Nested else-if
public void inputDataToElement(By by, String dataToInput) {

WebElement ele = driver.findElement(by);
WebElement ele = DriverManager.getDriver().findElement(by);
String tagName = ele.getTagName();

if (tagName.equals("select")) {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/znsio/rpap/pages/WebExample.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.znsio.rpap.pages;

import com.znsio.rpap.utils.DriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class WebExample extends BasePage {

public WebExample(WebDriver driver, WebDriverWait wait) {
super(driver, wait);
super(DriverManager.getDriver(), wait);
pageLoadWait(wait);
}

Expand All @@ -19,21 +20,21 @@ public WebExample(WebDriver driver, WebDriverWait wait) {


public String pageTitle() {
return driver.getTitle();
return DriverManager.getDriver().getTitle();
}

public void login(String username, String password) throws InterruptedException {
inputDataToElement(usernameField, username);
inputDataToElement(passwordField, password);
driver.findElement(submitButton).click();
DriverManager.getDriver().findElement(submitButton).click();
Thread.sleep(200);
}

public String getPostSubmitMessage() {
if (driver.findElements(postSubmitErrorMessage).size() > 0) {
return driver.findElement(postSubmitErrorMessage).getText();
if (DriverManager.getDriver().findElements(postSubmitErrorMessage).size() > 0) {
return DriverManager.getDriver().findElement(postSubmitErrorMessage).getText();
} else {
return driver.findElement(postSubmitSuccessMessage).getText();
return DriverManager.getDriver().findElement(postSubmitSuccessMessage).getText();
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/znsio/rpap/utils/DriverFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class DriverFactory {
public static final String WEB = "web";
private static final Logger LOGGER = Logger.getLogger(DriverFactory.class.getName());
private static final Properties config = Config.loadProperties(System.getProperty("CONFIG"));
private static WebDriver webDriver;
private static AppiumDriverLocalService localAppiumServer;
private static String APPIUM_SERVER_URL;

Expand Down Expand Up @@ -58,7 +57,7 @@ public static AppiumDriver getAppDriver() throws MalformedURLException {

public static void killDriver() {
if (getPlatform().equals(WEB)) {
webDriver.quit();
DriverManager.getDriver().quit();
} else {
stopAppiumServer();
}
Expand All @@ -69,19 +68,20 @@ public static String getPlatform() {
}

private static WebDriver launchWebApplication(String browserName, String appURL) {
WebDriver webDriver;
if (browserName.equalsIgnoreCase("firefox")) {
webDriver = new FirefoxDriver();
} else {
webDriver = new ChromeDriver();
}
webDriver.get(appURL);
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
return webDriver;
DriverManager.addDriver(webDriver);
return DriverManager.getDriver();
}

private static AppiumDriver launchMobileApplication(String platform, String automationDriver, String appPackage,
String appActivity, String appPackageLocation) throws MalformedURLException {
private static AppiumDriver launchMobileApplication(String platform, String automationDriver, String
appPackage, String appActivity, String appPackageLocation) throws MalformedURLException {
if (getPlatform().equals(ANDROID)) {
String dynamicAppiumUrl = startAppiumServer();
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/znsio/rpap/utils/DriverManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.znsio.rpap.utils;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import org.openqa.selenium.WebDriver;

public class DriverManager {

private static ThreadLocal<WebDriver> drivers = new ThreadLocal<>();
private static ThreadLocal<AppiumDriver> appiumDrivers = new ThreadLocal<>();
private static ThreadLocal<String> tagName = new ThreadLocal<>();

public static void addDriver(WebDriver driver) {
drivers.set(driver);
}

public static WebDriver getDriver() {
return drivers.get();
}

public static void addAppiumService(AppiumDriver driver) {
appiumDrivers.set(driver);
}

public static AppiumDriver getAppiumService() {
return appiumDrivers.get();
}

public static void addTagNAme(String tagname) {
tagName.set(tagname);
}

public static String getTagName() {
return tagName.get();
}

}
2 changes: 1 addition & 1 deletion src/test/java/com/znsio/rpap/AppExampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AppExampleTest extends BaseTest {
private void handleCalculatorPopUps() {
logInfoMessage("Inside @BeforeMethod of " + AppExampleTest.class.getSimpleName());
appPage = page.getClassInstance(AppExample.class);
appBL = new AppBL((AppiumDriver) driver, appPage, eyesOnApp);
appBL = new AppBL((AppiumDriver) driver, appPage, applitoolsInitializer.getAppEyes());
logInfoMessage("Handling if any popUps are shown in the app");
appPage.handlePopupIfPresent();
appPage.clearScreen();
Expand Down
46 changes: 32 additions & 14 deletions src/test/java/com/znsio/rpap/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,67 @@
package com.znsio.rpap;

import com.znsio.applitools.integration.ApplitoolsInitializer;
import com.znsio.rpap.pages.Page;
import com.znsio.rpap.utils.DriverFactory;
import io.appium.java_client.AppiumDriver;
import org.apache.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import com.znsio.rpap.pages.Page;
import com.znsio.rpap.utils.DriverFactory;
import org.testng.xml.XmlTest;

import java.io.IOException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;

import static com.znsio.reportportal.integration.utils.ReportPortalLogger.logInfoMessage;
import static com.znsio.rpap.utils.DriverFactory.WEB;

public class BaseTest extends ApplitoolsInitializer {
protected static WebDriver driver;
public class BaseTest {
protected WebDriver driver;
protected AppiumDriver appiumDriver;
private static WebDriverWait wait;
private static final Logger LOGGER = Logger.getLogger(BaseTest.class.getName());
protected Page page;
protected ApplitoolsInitializer applitoolsInitializer;

@BeforeSuite
public void suiteSetup() throws MalformedURLException {
public void suiteSetup(XmlTest suite) throws IOException {
logInfoMessage("Inside @BeforeSuite of " + BaseTest.class.getSimpleName());
applitoolsInitializer = new ApplitoolsInitializer();
applitoolsInitializer.setUpApplitoolsInitializer(suite);
}

@BeforeMethod
public void methodSetup(Method method) throws MalformedURLException {
logInfoMessage("Inside @BeforeMethod of " + BaseTest.class.getSimpleName());
driver = DriverFactory.getDriver();
wait = DriverFactory.getWait(driver);
logInfoMessage("Driver is ready");
page = new Page(driver, wait);
logInfoMessage("Page setup is completed");
if (DriverFactory.getPlatform().equals(WEB)) {
ApplitoolsInitializer.driverSetupForApplitoolsInitializer(driver);
applitoolsInitializer.driverSetupForApplitoolsInitializer(driver);
} else {
ApplitoolsInitializer.driverSetupForApplitoolsInitializer((AppiumDriver) driver);
applitoolsInitializer.driverSetupForApplitoolsInitializer((AppiumDriver) driver);
}
logInfoMessage("Driver is ready");
applitoolsInitializer.initiateApplitoolsInitializer(method, driver);
}

@BeforeMethod
public void methodSetup() {
page = new Page(driver, wait);
logInfoMessage("Page setup is completed");
@AfterMethod
public void methodTearDown(ITestResult iTestResult, Method method) {
logInfoMessage("Inside @AfterMethod of " + BaseTest.class.getSimpleName());
applitoolsInitializer.closeApplitoolsInitializer(iTestResult);
DriverFactory.killDriver();
}

@AfterSuite
public void suiteTearDown() {
logInfoMessage("Killing driver");
DriverFactory.killDriver();
logInfoMessage("Inside @AfterSuite of " + BaseTest.class.getSimpleName());
applitoolsInitializer.closeBatch();
}
}
16 changes: 6 additions & 10 deletions src/test/java/com/znsio/rpap/WebExampleTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.znsio.rpap;

import com.znsio.rpap.pages.WebExample;
import com.znsio.rpap.businessLayer.WebBL;
import com.znsio.rpap.pages.WebExample;
import com.znsio.rpap.utils.JsonDataManager;
import com.znsio.rpap.utils.JsonDataProvider;
import org.testng.annotations.BeforeMethod;
Expand All @@ -23,33 +23,29 @@ public void webPageSetup() {

logInfoMessage("Inside @BeforeMethod of " + WebExampleTest.class.getSimpleName());
webPage = page.getClassInstance(WebExample.class);
webBL = new WebBL(driver, webPage, eyesOnWeb);
webBL = new WebBL(driver, webPage, applitoolsInitializer.getWebEyes());
}

@Test(dataProvider = "getFromJson", priority = -1, description = "Validate Title of the Screen",
groups = {"visual"})
@Test(dataProvider = "getFromJson", priority = -1, description = "Validate Title of the Screen", groups = {"visual"})
public void titleTest(String title) {
webBL.verifyPageTitle(title);
}

@Test(dataProvider = "getFromJson", description = "Validating login with valid username and password",
groups = {"visual"})
@Test(dataProvider = "getFromJson", description = "Validating login with valid username and password", groups = {"visual"})
public void validLoginTest(String username, String password, String expectedMessage) throws InterruptedException {

webBL.performLogin(username, password);
webBL.verifyMessageAfterLogin(expectedMessage);
}

@Test(dataProvider = "getFromJson", description = "Validating login with invalid username and valid password",
groups = {"visual"})
@Test(dataProvider = "getFromJson", description = "Validating login with invalid username and valid password", groups = {"visual"})
public void invalidUserTest(String username, String password, String expectedMessage) throws InterruptedException {

webBL.performLogin(username, password);
webBL.verifyMessageAfterLogin(expectedMessage);
}

@Test(dataProvider = "getFromJson", description = "Validate login with valid username and invalid password",
groups = {"visual"})
@Test(dataProvider = "getFromJson", description = "Validate login with valid username and invalid password", groups = {"visual"})
public void invalidPasswordTest(String username, String password, String expectedMessage)
throws InterruptedException {

Expand Down
8 changes: 5 additions & 3 deletions src/test/resources/applitools.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
SERVER_URL=https://eyes.applitools.com/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not change anything in applitools.properties

SERVER_URL=https://jioeyes.applitools.com/
CONCURRENCY=5
MATCH_LEVEL=strict
SEND_DOM=true
STITCH_MODE=css
TAKE_FULL_PAGE_SCREENSHOT=true
VIEWPORT_SIZE=1200x700
USE_UFG=true
USE_UFG=false
SHOW_LOGS=false
SAVE_BASELINE_FOR_NEW_TESTS=false
FAIL_TEST_WHEN_DIFFERENCE_FOUND=true
FAIL_TEST_WHEN_DIFFERENCE_FOUND=true


2 changes: 1 addition & 1 deletion src/test/resources/config/androidConfig.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ IS_LOCAL_DEVICE=true
AUTOMATION_DRIVER=uiautomator2
APP_PACKAGE_NAME=com.android2.calculator3
APP_ACTIVITY=com.android2.calculator3.Calculator
APP_PACKAGE_LOCATION=https://github.com/anandbagmar/sampleAppsForNativeMobileAutomation/raw/main/AndroidCalculator.apk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not change APP_PACKAGE_LOCATION

APP_PACKAGE_LOCATION=drivers/AndroidCalculator.apk
PAGE_LOAD_TIME=30
RUN_IN_CI=false
BUILD_ID=BUILD_BUILDID
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/config/webConfig.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PLATFORM=web
TARGET_ENVIRONMENT=local
TEST_DATA_FILE=./src/test/resources/testdata/WebAutomationData.json
APPLITOOLS_CONFIGURATION_FILE=./src/test/resources/applitools.properties
IS_VISUAL=true
IS_VISUAL=false
TEST_REPORT_DIRECTORY=TestReport
RUN_IN_CI=false
BUILD_ID=BUILD_BUILDID
Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/reportportal.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rp.endpoint=<Your ReportPortal Endpoint>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert these changes - as these are Jio specific changes

rp.uuid=<Your ReportPortal Team's UDID>
rp.launch=RPAP_TEST_EXAMPLE
rp.project=<Your Report Portal Project's Name>
rp.endpoint=http://reportportal.jio.com
rp.uuid=8a7a54c7-7bff-49bf-a40a-a8e75c7ae1ee
rp.launch=qecc_TEST_EXAMPLE
rp.project=qecc
rp.enable=true
rp.description=Automation Scenarios examples for ReportPortal & Applitools integration
rp.convertimage=false
Expand Down