Skip to content

Commit

Permalink
Merge pull request #13 from deepaktiwariyml/fix/workflow
Browse files Browse the repository at this point in the history
Fix/workflow
  • Loading branch information
deepaktiwariyml authored Oct 28, 2024
2 parents 6185098 + d7ba99f commit 049be61
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 31 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/verify_android_browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: verify Android App Automation Workflow

on:
workflow_dispatch:
jobs:
job_id:

permissions:
contents: 'read'
id-token: 'write'

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Get current date
id: date
uses: Kaven-Universe/github-action-current-date-time@v1
with:
format: "YYYY-MM-DD"
- name: BrowserStack Env Setup
uses: 'browserstack/github-actions/setup-env@master'
with:
username: ${{ secrets.BROWSERSTACK_USERNAME }}
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
- name: Upload iOS App
id: ios_app_upload
uses: fjogeleit/http-request-action@v1
with:
url: https://api-cloud.browserstack.com/app-automate/upload
method: POST
username: ${{ secrets.BROWSERSTACK_USERNAME }}
password: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
data: '{ "custom_id": "SAMPLE_ANDROID_APP" }'
files: '{ "file": "${{ github.workspace }}/src/main/resources/android/apps/wdio.apk" }'
- name: test with Maven
run: mvn clean test "-DreportTitle=Sample Android Automation Test Report" -DrunMode=cloud -Dplatform=android -DsuiteFile=testng.xml
- name: Check Automation report was generated
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "reports/test-suite-report.html"
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: test_execution_results
path: reports/

- name: send summary report email
uses: dawidd6/action-send-mail@v3
if: always()
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.EMAIL_USERNAME }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: 'sample Android Automation Test Report - ${{ steps.date.outputs.time }}'
body: Build job of ${{github.repository}} completed successfully.Below is the Result summary. for Complete Details, Download the attached report.
html_body: file://target/surefire-reports/emailable-report.html
to: ${{ secrets.EMAIL_RECIPIENT_LIST }}
cc: ${{ secrets.EMAIL_CC_LIST }}
from: ${{ secrets.EMAIL_USERNAME }}
attachments: reports/test-suite-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public WelcomeScreen(WebDriver driver, Logger logger) {
@iOSXCUITFindBy(xpath = "//XCUIElementTypeCell[contains(@name,'tutorialCell')]//child::XCUIElementTypeImage")
public WebElement scLogo;

@FindBy(id="web-locator")
@AndroidFindBy(id = "com.saloncentric.app:id/iv_tutorial")
@iOSXCUITFindBy(xpath = "//XCUIElementTypeCell[contains(@name,'tutorialCell')]//child::XCUIElementTypeImage")
public WebElement splashScreenImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
import io.cucumber.java.en_scouse.An;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
Expand Down Expand Up @@ -194,35 +195,59 @@ public synchronized AndroidDriver androidDriver(String buildPath) throws Malform
MutableCapabilities sauceOptions = new MutableCapabilities();
File app = new File(buildPath);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", platform.getPlatformDeviceName());
capabilities.setCapability("appium:platformName", platform.getPlatformName());
capabilities.setCapability("appPackage", appPackage);
capabilities.setCapability("appActivity", appActivity);
//capabilities.setCapability("name", methodName.getName());

if (freshInstall)
capabilities.setCapability("app", app.getAbsolutePath());

capabilities.setCapability("chromedriverExecutable", chromeDriverPathMac); //webview handling
capabilities.setCapability("chromeOptions", new JSONObject().put("w3c", false));
capabilities.setCapability("autoGrantPermissions", true);
// added "MobileCapabilityType.FULL_RESET" capability to start app in fresh state (logout).
// Remove it if not required
capabilities.setCapability("appium:noReset", noResetFlag);
capabilities.setCapability("appium:automationName", "UiAutomator2");
if (executionMode.equalsIgnoreCase("cloud")) {
sauceOptions.setCapability("username", "oauth-deepak.tiwari-69b6f");
sauceOptions.setCapability("accessKey", "f1f00935-2049-45f6-b311-e65a533bd16d");
sauceOptions.setCapability("build", "appium-build-U12N8");
capabilities.setCapability("sauce:options", sauceOptions);
}
logger.info("Desired Capabilities " + new JSONObject(capabilities.asMap()));
String fileLocation=null;
Properties cloudProps=new Properties();

if (executionMode.equalsIgnoreCase("cloud")) {
URL saucelabUrl = new URL("https://oauth-deepak.tiwari-69b6f:f1f00935-2049-45f6-b311-e65a533bd16d@ondemand.us-west-1.saucelabs.com:443/wd/hub");
driver = new AndroidDriver(saucelabUrl, capabilities);
try {
fileLocation = "//src//main//resources//android//cloud-execution.properties";
InputStream platformProps = new FileInputStream(CommonUtil.getProjectDir() + fileLocation);
// load a properties file
cloudProps.load(platformProps);
} catch (Exception e) {
throw new RuntimeException("IOS Cloud Properties file not Found at "+fileLocation);
}
logger.info("Execution mode is Browserstack");
HashMap<String, Object> bstackOptions = new HashMap<String, Object>();
bstackOptions.put("userName", cloudProps.getProperty("BS.USERNAME"));
bstackOptions.put("accessKey", cloudProps.getProperty("BS.ACCESS_KEY"));
bstackOptions.put("appiumVersion", cloudProps.getProperty("BS.APPIUM_VERSION"));
capabilities.setCapability("platformName", "android");
capabilities.setCapability("appium:platformVersion", cloudProps.getProperty("BS.PLATFORM_VERSION"));
capabilities.setCapability("appium:deviceName", cloudProps.getProperty("BS.DEVICE_NAME"));
capabilities.setCapability("appium:app", cloudProps.getProperty("BS.APP"));
capabilities.setCapability("bstack:options", bstackOptions);
driver = new AndroidDriver(new URL("http://hub-cloud.browserstack.com/wd/hub"), capabilities);
}else {
capabilities.setCapability("deviceName", platform.getPlatformDeviceName());
capabilities.setCapability("appium:platformName", platform.getPlatformName());
capabilities.setCapability("appPackage", appPackage);
capabilities.setCapability("appActivity", appActivity);
//capabilities.setCapability("name", methodName.getName());

if (freshInstall)
capabilities.setCapability("app", app.getAbsolutePath());

capabilities.setCapability("chromedriverExecutable", chromeDriverPathMac); //webview handling
capabilities.setCapability("chromeOptions", new JSONObject().put("w3c", false));
capabilities.setCapability("autoGrantPermissions", true);
// added "MobileCapabilityType.FULL_RESET" capability to start app in fresh state (logout).
// Remove it if not required
capabilities.setCapability("appium:noReset", noResetFlag);
capabilities.setCapability("appium:automationName", "UiAutomator2");
if (executionMode.equalsIgnoreCase("cloud")) {
sauceOptions.setCapability("username", "oauth-deepak.tiwari-69b6f");
sauceOptions.setCapability("accessKey", "f1f00935-2049-45f6-b311-e65a533bd16d");
sauceOptions.setCapability("build", "appium-build-U12N8");
capabilities.setCapability("sauce:options", sauceOptions);
}
logger.info("Desired Capabilities " + new JSONObject(capabilities.asMap()));
if (executionMode.equalsIgnoreCase("cloud")) {
URL saucelabUrl = new URL("https://oauth-deepak.tiwari-69b6f:f1f00935-2049-45f6-b311-e65a533bd16d@ondemand.us-west-1.saucelabs.com:443/wd/hub");
driver = new AndroidDriver(saucelabUrl, capabilities);
} else
driver = new AndroidDriver(appiumService.getUrl(), capabilities);
}
else
driver = new AndroidDriver(appiumService.getUrl(), capabilities);
//Implicit waits
// driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
// AndroidDriver driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
Expand Down
Binary file added src/main/resources/android/apps/wdio.apk
Binary file not shown.
6 changes: 6 additions & 0 deletions src/main/resources/android/cloud-execution.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BS.USERNAME=ctqa2
BS.ACCESS_KEY=1Upj3Fh8x5HDf9haEWZ4
BS.APPIUM_VERSION=2.4.1
BS.PLATFORM_VERSION=12.0
BS.DEVICE_NAME=Samsung Galaxy S22 Ultra
BS.APP=SAMPLE_ANDROID_APP
4 changes: 2 additions & 2 deletions src/main/resources/config.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#automation Platform can be android or ios,web,api
AutomationPlatform=web
AutomationPlatform=android
UiEnv=staging
ApiEnv=staging
#execution mode can be local or cloud
ExecutionMode=local
ExecutionMode=cloud
AppiumJsPathMac=/Users/deepaktiwari/node_modules/appium/build/lib/main.js
AppiumJsPathWindows=/usr/local/lib/node_modules/appium/build/lib/main.js
AppiumJsPathLinux=/usr/local/lib/node_modules/appium/build/lib/main.js
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/ios/cloud-execution.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ BS.ACCESS_KEY=1Upj3Fh8x5HDf9haEWZ4
BS.APPIUM_VERSION=2.4.1
BS.PLATFORM_VERSION=16
BS.DEVICE_NAME=iPhone 14 Pro Max
BS.APP=PWC_IOS_AUT
BS.APP=SAMPLE_IOS_APP
1 change: 1 addition & 0 deletions src/test/java/com/yml/ios/TS_YML_SampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class TS_YML_SampleTest extends TS_YML_UI_BaseTest {
@Test
public void firstFailedTest() throws Exception {


this.currentTestCase.info("Executing first Test");
Assert.assertTrue(false);

Expand Down
4 changes: 3 additions & 1 deletion src/test/java/com/yml/ios/TS_YML_UI_BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.inject.Inject;
import com.yml.framework.aut.pojo.User;
import com.yml.framework.aut.screens.BaseScreen;
import com.yml.framework.aut.screens.WelcomeScreen;
import com.yml.framework.common.CommonUtil;
import com.yml.framework.common.Platform;
import com.yml.framework.common.RequestUtil;
Expand Down Expand Up @@ -53,7 +54,8 @@ public class TS_YML_UI_BaseTest {
public RequestUtil requestUtil;



@Inject
public WelcomeScreen welcomeScreen;
@Inject
public ExtentReports extent;

Expand Down

0 comments on commit 049be61

Please sign in to comment.