How to use AzureManager class of com.qaprosoft.azure package

Best Carina code snippet using com.qaprosoft.azure.AzureManager

Source:CarinaListener.java Github

copy

Full Screen

...53import com.amazonaws.services.s3.model.S3ObjectSummary;54import com.azure.storage.blob.models.BlobProperties;55import com.qaprosoft.amazon.AmazonS3Manager;56import com.qaprosoft.appcenter.AppCenterManager;57import com.qaprosoft.azure.AzureManager;58import com.qaprosoft.carina.browsermobproxy.ProxyPool;59import com.qaprosoft.carina.core.foundation.commons.SpecialKeywords;60import com.qaprosoft.carina.core.foundation.report.ReportContext;61import com.qaprosoft.carina.core.foundation.report.TestResultItem;62import com.qaprosoft.carina.core.foundation.report.TestResultType;63import com.qaprosoft.carina.core.foundation.report.email.EmailReportGenerator;64import com.qaprosoft.carina.core.foundation.report.email.EmailReportItemCollector;65import com.qaprosoft.carina.core.foundation.report.qtest.IQTestManager;66import com.qaprosoft.carina.core.foundation.report.testrail.ITestRailManager;67import com.qaprosoft.carina.core.foundation.skip.ExpectedSkipManager;68import com.qaprosoft.carina.core.foundation.utils.Configuration;69import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;70import com.qaprosoft.carina.core.foundation.utils.DateUtils;71import com.qaprosoft.carina.core.foundation.utils.FileManager;72import com.qaprosoft.carina.core.foundation.utils.Messager;73import com.qaprosoft.carina.core.foundation.utils.R;74import com.qaprosoft.carina.core.foundation.utils.ZebrunnerNameResolver;75import com.qaprosoft.carina.core.foundation.utils.ownership.Ownership;76import com.qaprosoft.carina.core.foundation.utils.resources.L10N;77import com.qaprosoft.carina.core.foundation.utils.tag.PriorityManager;78import com.qaprosoft.carina.core.foundation.utils.tag.TagManager;79import com.qaprosoft.carina.core.foundation.webdriver.CarinaDriver;80import com.qaprosoft.carina.core.foundation.webdriver.Screenshot;81import com.qaprosoft.carina.core.foundation.webdriver.TestPhase;82import com.qaprosoft.carina.core.foundation.webdriver.TestPhase.Phase;83import com.qaprosoft.carina.core.foundation.webdriver.core.capability.CapabilitiesLoader;84import com.qaprosoft.carina.core.foundation.webdriver.screenshot.AutoScreenshotRule;85import com.qaprosoft.carina.core.foundation.webdriver.screenshot.IScreenshotRule;86import com.zebrunner.agent.core.registrar.Artifact;87import com.zebrunner.agent.core.registrar.CurrentTest;88import com.zebrunner.agent.core.registrar.CurrentTestRun;89import com.zebrunner.agent.core.registrar.Label;90import com.zebrunner.agent.core.registrar.TestRail;91import com.zebrunner.agent.core.registrar.label.CompositeLabelResolver;92import com.zebrunner.agent.core.registrar.maintainer.ChainedMaintainerResolver;93import com.zebrunner.agent.core.webdriver.RemoteWebDriverFactory;94import com.zebrunner.agent.testng.core.testname.TestNameResolverRegistry;95/*96 * CarinaListener - base carina-core TestNG Listener.97 *98 * @author Vadim Delendik99 */100public class CarinaListener extends AbstractTestListener implements ISuiteListener, IQTestManager, ITestRailManager, IClassListener {101 private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());102 protected static final long EXPLICIT_TIMEOUT = Configuration.getLong(Parameter.EXPLICIT_TIMEOUT);103 protected static final String SUITE_TITLE = "%s%s%s - %s (%s)";104 protected static final String XML_SUITE_NAME = " (%s)";105 protected static boolean automaticDriversCleanup = true;106 107 protected boolean isRunLabelsRegistered = false;108 109 110 private static final Pattern S3_BUCKET_PATTERN = Pattern.compile("s3:\\/\\/([a-zA-Z-0-9][^\\/]*)\\/(.*)");111 private static final Pattern AZURE_CONTAINER_PATTERN = Pattern.compile("\\/\\/([a-z0-9]{3,24})\\.blob.core.windows.net\\/(?:(\\$root|(?:[a-z0-9](?!.*--)[a-z0-9-]{1,61}[a-z0-9]))\\/)?(.{1,1024})");112 // appcenter://appName/platformName/buildType/version113 private static final Pattern APPCENTER_PATTERN = Pattern.compile(114 "appcenter:\\/\\/([a-zA-Z-0-9][^\\/]*)\\/([a-zA-Z-0-9][^\\/]*)\\/([a-zA-Z-0-9][^\\/]*)\\/([a-zA-Z-0-9][^\\/]*)");115 public CarinaListener() {116 // Add shutdown hook117 Runtime.getRuntime().addShutdownHook(new ShutdownHook());118 // Zebrunner core java agent is user for capturing events of RemoteDriverSession instances.119 // Internally, the agent uses java instrumentation agent for its purposes.120 // The instrumentation agent implicitly triggers initialization of the R class because it uses logger.121 // Carina has the ThreadLogAppender class which is closely related to logging and internally uses the R class.122 // Technically, this happen when the maven-surefire-plugin has not set inherited program arguments (passed to mvn process).123 // That is why it is necessary to reinit R class here when TestNG loads the CarinaListener class.124 R.reinit();125 126 LOGGER.info(Configuration.asString());127 // Configuration.validateConfiguration();128 try {129 L10N.load();130 } catch (Exception e) {131 LOGGER.error("L10N bundle is not initialized successfully!", e);132 }133 // declare global capabilities in configuration if custom_capabilities is declared134 String customCapabilities = Configuration.get(Parameter.CUSTOM_CAPABILITIES);135 if (!customCapabilities.isEmpty()) {136 // redefine core CONFIG properties using global custom capabilities file137 new CapabilitiesLoader().loadCapabilities(customCapabilities);138 }139 // declare global capabilities from Zebrunner Launcher if any140 Capabilities zebrunnerCapabilities = RemoteWebDriverFactory.getCapabilities();141 if (!zebrunnerCapabilities.asMap().isEmpty()) {142 // redefine core CONFIG properties using caps from Zebrunner launchers143 new CapabilitiesLoader().loadCapabilities(zebrunnerCapabilities);144 }145 IScreenshotRule autoScreenshotsRule = (IScreenshotRule) new AutoScreenshotRule();146 Screenshot.addScreenshotRule(autoScreenshotsRule);147 TestNameResolverRegistry.set(new ZebrunnerNameResolver());148 CompositeLabelResolver.addResolver(new TagManager());149 CompositeLabelResolver.addResolver(new PriorityManager());150 ReportContext.getBaseDir(); // create directory for logging as soon as possible151 }152 @Override153 public void onStart(ISuite suite) {154 LOGGER.debug("CarinaListener->onStart(ISuite suite)");155 // first means that ownership/maintainer resolver from carina has higher priority156 ChainedMaintainerResolver.addFirst(new Ownership(suite.getParameter("suiteOwner")));157 if (!"INFO".equalsIgnoreCase(Configuration.get(Parameter.CORE_LOG_LEVEL))) {158 LoggerContext ctx = (LoggerContext) LogManager.getContext(this.getClass().getClassLoader(), false);159 org.apache.logging.log4j.core.config.Configuration config = ctx.getConfiguration();160 // make sure to update after moving to "com.zebrunner"161 LoggerConfig logger = config.getLoggerConfig("com.qaprosoft.carina.core");162 logger.setLevel(Level.getLevel(Configuration.get(Parameter.CORE_LOG_LEVEL)));163 }164 updateAppPath();165 166 setThreadCount(suite);167 168 if (Configuration.getPlatform().equalsIgnoreCase(SpecialKeywords.API)) {169 CurrentTestRun.setPlatform(SpecialKeywords.API);170 }171 String mobileApp = Configuration.getMobileApp();172 if (!mobileApp.isEmpty()) {173 // [VD] do not move into the static block as Zebrunner reporting need registered test run!174 Artifact.attachReferenceToTestRun("app", mobileApp);175 }176 // register app_version/build as artifact if available...177 Configuration.setBuild(Configuration.get(Parameter.APP_VERSION));178 179 String sha1 = Configuration.get(Parameter.GIT_HASH);180 if (!sha1.isEmpty()) {181 Label.attachToTestRun("sha1", sha1);182 }183 184 /*185 * To support multi-suite declaration as below we have to init test run labels at once only!186 * <suite-files>187 * <suite-file path="suite1.xml"/>188 * <suite-file path="suite2.xml"/>189 * </suite-files>190 */191 192 if (!this.isRunLabelsRegistered) {193 attachTestRunLabels(suite);194 this.isRunLabelsRegistered = true;195 }196 LOGGER.info("CARINA_CORE_VERSION: " + getCarinaVersion());197 }198 @Override199 public void onStart(ITestContext context) {200 LOGGER.debug("CarinaListener->OnTestStart(ITestContext context): " + context.getName());201 super.onStart(context);202 }203 @Override204 public void beforeConfiguration(ITestResult result) {205 LOGGER.debug("CarinaListener->beforeConfiguration");206 super.beforeConfiguration(result);207 // remember active test phase to organize valid driver pool manipulation208 // process209 if (result.getMethod().isBeforeSuiteConfiguration()) {210 TestPhase.setActivePhase(Phase.BEFORE_SUITE);211 }212 if(result.getMethod().isBeforeTestConfiguration()){213 TestPhase.setActivePhase(Phase.BEFORE_TEST);214 }215 if (result.getMethod().isBeforeClassConfiguration()) {216 TestPhase.setActivePhase(Phase.BEFORE_CLASS);217 }218 if (result.getMethod().isBeforeMethodConfiguration()) {219 TestPhase.setActivePhase(Phase.BEFORE_METHOD);220 }221 if (result.getMethod().isAfterMethodConfiguration()) {222 TestPhase.setActivePhase(Phase.AFTER_METHOD);223 }224 if (result.getMethod().isAfterClassConfiguration()) {225 TestPhase.setActivePhase(Phase.AFTER_CLASS);226 }227 if (result.getMethod().isAfterTestConfiguration()){228 TestPhase.setActivePhase(Phase.AFTER_TEST);229 }230 if (result.getMethod().isAfterSuiteConfiguration()) {231 TestPhase.setActivePhase(Phase.AFTER_SUITE);232 }233 }234 @Override235 public void onConfigurationFailure(ITestResult result) {236 LOGGER.debug("CarinaListener->onConfigurationFailure");237 super.onConfigurationFailure(result);238 }239 @Override240 public void onTestStart(ITestResult result) {241 LOGGER.debug("CarinaListener->onTestStart");242 TestPhase.setActivePhase(Phase.METHOD);243 // handle expected skip244 Method testMethod = result.getMethod().getConstructorOrMethod().getMethod();245 if (ExpectedSkipManager.getInstance().isSkip(testMethod, result.getTestContext())) {246 skipExecution("Based on rule listed above");247 }248 super.onTestStart(result);249 }250 @Override251 public void onTestSuccess(ITestResult result) {252 LOGGER.debug("CarinaListener->onTestSuccess");253 onTestFinish(result);254 super.onTestSuccess(result);255 }256 @Override257 public void onTestFailure(ITestResult result) {258 LOGGER.debug("CarinaListener->onTestFailure");259 String errorMessage = getFailureReason(result);260 takeScreenshot("TEST FAILED - " + errorMessage);261 onTestFinish(result);262 super.onTestFailure(result);263 }264 @Override265 public void onTestSkipped(ITestResult result) {266 LOGGER.debug("CarinaListener->onTestSkipped");267 String errorMessage = getFailureReason(result);268 takeScreenshot("TEST SKIPPED - " + errorMessage, false);269 onTestFinish(result);270 super.onTestSkipped(result);271 }272 private boolean hasDependencies(ITestResult result) {273 String methodName = result.getMethod().getMethodName();274 String className = result.getMethod().getTestClass().getName();275 // analyze all suite methods and return true if any of them depends on276 // existing method277 List<ITestNGMethod> methods = result.getTestContext().getSuite().getAllMethods();278 for (ITestNGMethod method : methods) {279 List<String> dependencies = Arrays.asList(method.getMethodsDependedUpon());280 if (dependencies.contains(methodName) ||281 dependencies.contains(className + "." + methodName)) {282 LOGGER.debug("dependency detected for " + methodName);283 return true;284 }285 }286 return false;287 }288 private void onTestFinish(ITestResult result) {289 try {290 // clear all kind of temporary properties291 R.CONFIG.clearTestProperties();292 R.TESTDATA.clearTestProperties();293 R.DATABASE.clearTestProperties();294 R.EMAIL.clearTestProperties();295 R.REPORT.clearTestProperties();296 R.ZAFIRA.clearTestProperties();297 LOGGER.debug("Test result is : " + result.getStatus());298 // result status == 2 means failure, status == 3 means skip. We need to quit driver anyway for failure and skip299 if ((automaticDriversCleanup && !hasDependencies(result)) || result.getStatus() == 2 || result.getStatus() == 3) {300 if (!Configuration.getBoolean(Parameter.FORCIBLY_DISABLE_DRIVER_QUIT)) {301 quitDrivers(Phase.BEFORE_METHOD, Phase.METHOD);302 }303 }304 attachTestLabels(result);305 } catch (Exception e) {306 LOGGER.error("Exception in CarinaListener->onTestFinish!", e);307 }308 }309 @Override310 public void onAfterClass(ITestClass testClass){311 LOGGER.debug("CarinaListener->onAfterClass(ITestClass testClass)");312 quitDrivers(Phase.BEFORE_CLASS);313 }314 @Override315 public void onFinish(ITestContext context) {316 LOGGER.debug("CarinaListener->onFinish(ITestContext context)");317 super.onFinish(context);318 // [SZ] it's still needed to close driver from BeforeClass stage.319 // Otherwise it could be potentially used in other test classes 320// quitDrivers(Phase.BEFORE_CLASS); already exited in onAfterClass() method321 quitDrivers(Phase.BEFORE_TEST);322 LOGGER.debug("CarinaListener->onFinish(context): " + context.getName());323 }324 @Override325 public void onFinish(ISuite suite) {326 LOGGER.debug("CarinaListener->onFinish(ISuite suite)");327 try {328 String browser = getBrowser();329 // String suiteName = getSuiteName(context);330 String title = getTitle(suite.getXmlSuite());331 TestResultType testResult = EmailReportGenerator.getSuiteResult(EmailReportItemCollector.getTestResults());332 String status = testResult.getName();333 title = status + ": " + title;334 String env = "";335 if (!Configuration.isNull(Parameter.ENV)) {336 env = Configuration.get(Parameter.ENV);337 }338 if (!Configuration.get(Parameter.URL).isEmpty()) {339 env += " - <a href='" + Configuration.get(Parameter.URL) + "'>" + Configuration.get(Parameter.URL)340 + "</a>";341 }342 ReportContext.getTempDir().delete();343 // EmailReportItemCollector.getTestResults());344 LOGGER.debug("Generating email report...");345 // Generate emailable html report using regular method346 EmailReportGenerator report = new EmailReportGenerator(title, env, Configuration.get(Parameter.APP_VERSION),347 browser, DateUtils.now(), EmailReportItemCollector.getTestResults(),348 EmailReportItemCollector.getCreatedItems());349 String emailContent = report.getEmailBody();350 // Store emailable report under emailable-report.html351 ReportContext.generateHtmlReport(emailContent);352 printExecutionSummary(EmailReportItemCollector.getTestResults());353 LOGGER.debug("Finish email report generation.");354 } catch (Exception e) {355 LOGGER.error("Exception in CarinaListener->onFinish(ISuite suite)", e);356 }357 }358 /**359 * Disable automatic drivers cleanup after each TestMethod and switch to controlled by tests itself.360 * But anyway all drivers will be closed forcibly as only suite is finished or aborted 361 */362 public static void disableDriversCleanup() {363 LOGGER.info("Automatic drivers cleanup will be disabled!");364 automaticDriversCleanup = false;365 }366 protected String getBrowser() {367 return Configuration.getBrowser();368 }369 protected String getTitle(XmlSuite suite) {370 String browser = getBrowser();371 if (!browser.isEmpty()) {372 browser = " " + browser; // insert the space before373 }374 String env = !Configuration.isNull(Parameter.ENV) ? Configuration.get(Parameter.ENV)375 : Configuration.get(Parameter.URL);376 String title = "";377 String app_version = "";378 if (!Configuration.get(Parameter.APP_VERSION).isEmpty()) {379 // if nothing is specified then title will contain nothing380 app_version = Configuration.get(Parameter.APP_VERSION) + " - ";381 }382 String suiteName = getSuiteName(suite);383 String xmlFile = getSuiteFileName(suite);384 title = String.format(SUITE_TITLE, app_version, suiteName, String.format(XML_SUITE_NAME, xmlFile), env, browser);385 return title;386 }387 private String getSuiteFileName(XmlSuite suite) {388 // TODO: investigate why we need such method and suite file name at all389 String fileName = suite.getFileName();390 if (fileName == null) {391 fileName = "undefined";392 }393 LOGGER.debug("Full suite file name: " + fileName);394 if (fileName.contains("\\")) {395 fileName = fileName.replaceAll("\\\\", "/");396 }397 fileName = StringUtils.substringAfterLast(fileName, "/");398 LOGGER.debug("Short suite file name: " + fileName);399 return fileName;400 }401 protected String getSuiteName(XmlSuite suite) {402 String suiteName = "";403 if (suite != null && !"Default suite".equals(suite.getName())) {404 suiteName = Configuration.get(Parameter.SUITE_NAME).isEmpty() ? suite.getName()405 : Configuration.get(Parameter.SUITE_NAME);406 } else {407 suiteName = Configuration.get(Parameter.SUITE_NAME).isEmpty() ? R.EMAIL.get("title")408 : Configuration.get(Parameter.SUITE_NAME);409 }410 return suiteName;411 }412 private void printExecutionSummary(List<TestResultItem> tris) {413 Messager.INFORMATION.info("**************** Test execution summary ****************");414 int num = 1;415 for (TestResultItem tri : tris) {416 String failReason = tri.getFailReason();417 if (failReason == null) {418 failReason = "";419 }420 if (!tri.isConfig()) {421 String reportLinks = !StringUtils.isEmpty(tri.getLinkToScreenshots())422 ? "screenshots=" + tri.getLinkToScreenshots() + " | " : "";423 reportLinks += !StringUtils.isEmpty(tri.getLinkToLog()) ? "log=" + tri.getLinkToLog() : "";424 Messager.TEST_RESULT.info(String.valueOf(num++), tri.getTest(), tri.getResult().toString(),425 reportLinks);426 }427 }428 }429 @Deprecated430 protected void putS3Artifact(String key, String path) {431 AmazonS3Manager.getInstance().put(Configuration.get(Parameter.S3_BUCKET_NAME), key, path);432 }433 @Deprecated434 protected S3Object getS3Artifact(String bucket, String key) {435 return AmazonS3Manager.getInstance().get(Configuration.get(Parameter.S3_BUCKET_NAME), key);436 }437 @Deprecated438 protected S3Object getS3Artifact(String key) {439 return getS3Artifact(Configuration.get(Parameter.S3_BUCKET_NAME), key);440 }441 @Deprecated442 protected void putAzureArtifact(String remotePath, String localPath) {443 AzureManager.getInstance().put(Configuration.get(Parameter.AZURE_CONTAINER_NAME), remotePath, localPath);444 }445 @Deprecated446 protected void getAzureArtifact(String bucket, String remotePath, File localPath) {447 AzureManager.getInstance().download(bucket, remotePath, localPath);448 }449 private static void updateAppPath() {450 451 String mobileAppPath = Configuration.getMobileApp();452 Matcher matcher = S3_BUCKET_PATTERN.matcher(mobileAppPath);453 LOGGER.debug("Analyzing if mobile app is located on S3...");454 if (matcher.find()) {455 mobileAppPath = updateS3AppPath(mobileAppPath);456 }457 matcher = AZURE_CONTAINER_PATTERN.matcher(mobileAppPath);458 LOGGER.debug("Analyzing if mobile app is located on Azure...");459 if (matcher.find()) {460 mobileAppPath = updateAzureAppPath(mobileAppPath);461 }462 463 matcher = APPCENTER_PATTERN.matcher(mobileAppPath);464 LOGGER.debug("Analyzing if mobile_app is located on AppCenter...");465 if (matcher.find()) {466 mobileAppPath = updateAppCenterAppPath(mobileAppPath);467 }468 469 Configuration.setMobileApp(mobileAppPath);470 }471 /**472 * Method to update MOBILE_APP path in case if apk is located in Hockey App.473 */474 private static String updateAppCenterAppPath(String mobileAppPath) {475 Matcher matcher = APPCENTER_PATTERN.matcher(mobileAppPath);476 if (matcher.find()) {477 LOGGER.info("app artifact is located on AppCenter...");478 String appName = matcher.group(1);479 String platformName = matcher.group(2);480 String buildType = matcher.group(3);481 String version = matcher.group(4);482 //TODO: test if generated appcenter download url is valid483 mobileAppPath = AppCenterManager.getInstance().getDownloadUrl(appName, platformName, buildType,484 version);485 } else {486 LOGGER.error("Unable to parse '{}' path using AppCenter pattern", mobileAppPath);487 }488 return mobileAppPath;489 }490 /**491 * Method to update MOBILE_APP path in case if apk is located in s3 bucket.492 */493 private static String updateS3AppPath(String mobileAppPath) {494 // get app path to be sure that we need(do not need) to download app495 // from s3 bucket496 Matcher matcher = S3_BUCKET_PATTERN.matcher(mobileAppPath);497 if (matcher.find()) {498 LOGGER.info("app artifact is located on s3...");499 String bucketName = matcher.group(1);500 String key = matcher.group(2);501 Pattern pattern = Pattern.compile(key);502 // analyze if we have any pattern inside mobile_app to make extra503 // search in AWS504 int position = key.indexOf(".*");505 if (position > 0) {506 // /android/develop/dfgdfg.*/Mapmyrun.apk507 int slashPosition = key.substring(0, position).lastIndexOf("/");508 if (slashPosition > 0) {509 key = key.substring(0, slashPosition);510 S3ObjectSummary lastBuild = AmazonS3Manager.getInstance().getLatestBuildArtifact(bucketName, key,511 pattern);512 key = lastBuild.getKey();513 }514 } else {515 key = AmazonS3Manager.getInstance().get(bucketName, key).getKey();516 }517 LOGGER.info("next s3 app key will be used: " + key);518 // generate presign url explicitly to register link as run artifact519 long hours = 72L*1000*60*60; // generate presigned url for nearest 3 days520 mobileAppPath = AmazonS3Manager.getInstance().generatePreSignUrl(bucketName, key, hours).toString();521 } else {522 LOGGER.error("Unable to parse '{}' path using S3 pattern", mobileAppPath);523 }524 525 return mobileAppPath;526 }527 /**528 * Method to update MOBILE_APP path in case if apk is located in Azure storage.529 */530 private static String updateAzureAppPath(String mobileAppPath) {531 Matcher matcher = AZURE_CONTAINER_PATTERN.matcher(mobileAppPath);532 if (matcher.find()) {533 LOGGER.info("app artifact is located on Azure...");534 String accountName = matcher.group(1);535 String containerName = matcher.group(2) == null ? "$root" : matcher.group(2);536 String remoteFilePath = matcher.group(3);537 LOGGER.info(538 "Account: " + accountName + "\n" +539 "Container: " + containerName + "\n" +540 "RemotePath: " + remoteFilePath + "\n"541 );542 R.CONFIG.put(Parameter.AZURE_ACCOUNT_NAME.getKey(), accountName);543 BlobProperties blobProperties = AzureManager.getInstance().get(containerName, remoteFilePath);544 String azureLocalStorage = Configuration.get(Parameter.AZURE_LOCAL_STORAGE);545 String localFilePath = azureLocalStorage + File.separator + StringUtils.substringAfterLast(remoteFilePath, "/");546 File file = new File(localFilePath);547 try {548 // verify requested artifact by checking the checksum549 if (file.exists() && FileManager.getFileChecksum(FileManager.Checksum.MD5, file).equals(Base64.encodeBase64String(blobProperties.getContentMd5()))) {550 LOGGER.info("build artifact with the same checksum already downloaded: " + file.getAbsolutePath());551 } else {552 LOGGER.info(553 String.format("Following data was extracted: container: %s, remotePath: %s, local file: %s",554 containerName, remoteFilePath, file.getAbsolutePath())555 );556 AzureManager.getInstance().download(containerName, remoteFilePath, file);557 }558 } catch (Exception exception) {559 LOGGER.error("Azure app path update exception detected!", exception);560 }561 mobileAppPath = file.getAbsolutePath();562 // try to redefine app_version if it's value is latest or empty563 String appVersion = Configuration.get(Parameter.APP_VERSION);564 if (appVersion.equals("latest") || appVersion.isEmpty()) {565 Configuration.setBuild(file.getName());566 }567 } else {568 LOGGER.error("Unable to parse '{}' path using Azure pattern", mobileAppPath);569 }570 ...

Full Screen

Full Screen

Source:AzureManager.java Github

copy

Full Screen

...28import com.azure.storage.common.StorageSharedKeyCredential;29import com.qaprosoft.carina.core.foundation.commons.SpecialKeywords;30import com.qaprosoft.carina.core.foundation.crypto.CryptoTool;31import com.qaprosoft.carina.core.foundation.utils.Configuration;32public class AzureManager {33 private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());34 private static volatile AzureManager instance = null;35 private static BlobServiceClient blobServiceClient = null;36 private AzureManager() {}37 public synchronized static AzureManager getInstance() {38 if (instance == null) {39 instance = new AzureManager();40 CryptoTool cryptoTool = new CryptoTool(Configuration.getCryptoParams());41 Pattern CRYPTO_PATTERN = Pattern.compile(SpecialKeywords.CRYPT);42 String accountName = Configuration.get(Configuration.Parameter.AZURE_ACCOUNT_NAME);43 String endpoint = cryptoTool.decryptByPattern(Configuration.get(Configuration.Parameter.AZURE_BLOB_URL), CRYPTO_PATTERN);44 String secretKey = cryptoTool.decryptByPattern(Configuration.get(Configuration.Parameter.AZURE_ACCESS_KEY_TOKEN), CRYPTO_PATTERN);45 // Create a SharedKeyCredential46 StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, secretKey);47 // Create a blobServiceClient48 blobServiceClient = new BlobServiceClientBuilder()49 .endpoint(endpoint)50 .credential(credential)51 .buildClient();52 }53 return instance;...

Full Screen

Full Screen

Source:AzureClientTest.java Github

copy

Full Screen

...24import java.io.IOException;25import java.security.NoSuchAlgorithmException;26public class AzureClientTest {27 @Test()28 public void testAzureManagerInit() {29 Assert.assertNotNull(AzureManager.getInstance(), "Singleton for AzureManager is null!");30 }31 @Test(expectedExceptions = RuntimeException.class)32 public void testPutKeyNull() {33 AzureManager.getInstance().put("", null, null);34 Assert.fail("Key verification doesn't work!");35 }36 @Test(expectedExceptions = RuntimeException.class)37 public void testPutKeyEmpty() {38 AzureManager.getInstance().put("", "", null);39 Assert.fail("Key verification doesn't work!");40 }41 @Test(expectedExceptions = RuntimeException.class)42 public void testPutFilePathNull() {43 AzureManager.getInstance().put("", "test", null);44 Assert.fail("FilePath verification doesn't work!");45 }46 @Test(expectedExceptions = RuntimeException.class)47 public void testPutFilePathEmpty() {48 AzureManager.getInstance().put("", "test", "");49 Assert.fail("FilePath verification doesn't work!");50 }51 @Test(expectedExceptions = RuntimeException.class)52 public void testPutFilePathNotExist() {53 AzureManager.getInstance().put("", "test", "test");54 Assert.fail("File existence verification doesn't work!");55 }56 @Test(expectedExceptions = RuntimeException.class)57 public void testGetKeyNull() {58 String localPath = Configuration.get(Configuration.Parameter.AZURE_LOCAL_STORAGE);59 AzureManager.getInstance().download("resources", "apk-StableDev.apk", new File(localPath + "/apk-StableDev.apk"));60 Assert.fail("Key verification doesn't work!");61 }62 @Test(expectedExceptions = RuntimeException.class)63 public void testDeleteKeyNull() {64 AzureManager.getInstance().delete("", null);65 Assert.fail("Key verification doesn't work!");66 }67 @Test(expectedExceptions = RuntimeException.class)68 public void testDeleteKeyEmpty() {69 AzureManager.getInstance().delete("", "");70 Assert.fail("Key verification doesn't work!");71 }72 @Test(expectedExceptions = {RuntimeException.class, IOException.class, NoSuchAlgorithmException.class})73 public void testGetPropsNull() throws IOException, NoSuchAlgorithmException {74 String localPath = Configuration.get(Configuration.Parameter.AZURE_LOCAL_STORAGE);75 BlobProperties value = AzureManager.getInstance().get("resources", "apk-StableDev.apk");76 String remoteFileMD5 = Base64.encodeBase64String(value.getContentMd5());77 File file = new File("./apk-StableDev.apk");78 String localFileMD5 = FileManager.getFileChecksum(FileManager.Checksum.MD5, file);79 System.out.println(remoteFileMD5);80 System.out.println(localFileMD5);81 System.out.println(remoteFileMD5.equals(localFileMD5));82 Assert.fail("Key verification doesn't work!");83 }84}...

Full Screen

Full Screen

AzureManager

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.azure.*;2import com.microsoft.azure.management.resources.fluentcore.arm.Region;3import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;4import com.microsoft.azure.management.resources.fluentcore.model.Indexable;5import com.microsoft.azure.management.resources.fluentcore.model.Creatable;6import com.microsoft.azure.management.resources.fluentcore.arm.models.HasId;7import com.microsoft.azure.management.resources.fluentcore.arm.models.HasName;8import com.microsoft.azure.management.compute.implementation.ComputeManager;9import com.microsoft.azure.management.compute.ComputeManagementClient;10import com.microsoft.azure.management.compute.ComputeManagementService;11import com.microsoft.azure.management.compute.VirtualMachines;12import com.microsoft.azure.management.compute.VirtualMachine;13import com.microsoft.azure.management.compute.VirtualMachineSizeTypes;14import com.microsoft.azure.management.compute.VirtualMachineCustomImage;15import com.microsoft.azure.management.compute.VirtualMachineCustomImage.DefinitionStages.WithGroup;16import com.microsoft.azure.management.compute.VirtualMachineCustomImage.DefinitionStages.WithLinuxCreate;17import com.microsoft.azure.management.compute.VirtualMachineCustomImage.DefinitionStages.WithWindowsCreate;18import com.microsoft.azure.management.compute.VirtualMachineCustomImage.DefinitionStages.WithCreate;19import com.microsoft.azure.management.compute.implementation.VirtualMachineCustomImageInner;20import com.microsoft.azure.management.compute.implementation.VirtualMachineCustomImageImpl;21import com.microsoft.azure.management.resources.fluentcore.arm.Region;22import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;23import com.microsoft.azure.management.resources.fluentcore.model.Creatable;24import com.microsoft.azure.management.resources.fluentcore.model.Indexable;25import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;26import com.microsoft.azure.management.resources.fluentcore.arm.models.HasId;27import com.microsoft.azure.management.resources.fluentcore.arm.models.HasName;28import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;29import com.microsoft.azure.management.resources.fluentcore.model.implementation.IndexableWrapperImpl;30import com.microsoft.azure.management.resources.fluentcore.utils.Utils;31import com.microsoft.azure.management.storage.StorageAccount;32import com.microsoft.azure.management.storage.StorageAccounts;33import com.microsoft.azure.management.storage.implementation.StorageManager;34import com.microsoft.azure.management.storage.implementation.StorageManager.Authenticated;35import com.microsoft.azure.management.storage.implementation.StorageAccountsInner;36import com.microsoft.azure.management.storage.implementation.StorageManagementClient;37import com.microsoft.azure.management.storage.implementation.StorageManagementService;38import com.microsoft.azure.management.storage.implementation.StorageAccountsInner;39import com.microsoft.azure.management.storage.implementation.StorageAccountsImpl

Full Screen

Full Screen

AzureManager

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.azure.AzureManager;2import com.qaprosoft.azure.AzureManagerException;3import java.io.File;4import java.io.IOException;5import java.util.ArrayList;6import java.util.List;7import java.util.concurrent.ExecutionException;8import java.util.concurrent.TimeUnit;9import java.util.concurrent.TimeoutException;10import java.util.logging.Level;11import java.util.logging.Logger;12import org.apache.commons.io.FileUtils;13public class 1 {14 public static void main(String[] args) throws IOException, InterruptedException, ExecutionException, TimeoutException {15 try {16 AzureManager azureManager = new AzureManager();

Full Screen

Full Screen

AzureManager

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.azure.AzureManager;2import com.qaprosoft.azure.AzureManagerFactory;3import com.qaprosoft.azure.AzureManagerFactory.AzureManagerType;4import com.qaprosoft.azure.AzureManagerFactory.AzureRegion;5import com.qaprosoft.azure.AzureManagerFactory.AzureVMType;6import com.qaprosoft.azure.AzureVM;7import com.qaprosoft.azure.AzureVMSize;8import java.util.List;9public class AzureManagerTest {10public static void main(String[] args) {11AzureManager azureManager = AzureManagerFactory.getAzureManager(AzureManagerType.AZURE_MANAGEMENT, "your subscription id", "your pem file path", "your pem file password", AzureRegion.EAST_US);12List<AzureVM> vms = azureManager.getVMs();13for(AzureVM vm : vms) {14System.out.println(vm.getName());15}16AzureVM vm = azureManager.getVMByName("your vm name");17System.out.println(vm.getName());18azureManager.startVM(vm);19azureManager.stopVM(vm);20azureManager.restartVM(vm);21azureManager.deleteVM(vm);22azureManager.createVM(AzureVMType.WINDOWS, "your vm name", "your vm password", AzureVMSize.BASIC_A0);23}24}25import com.microsoft.windowsazure.Configuration;26import com.microsoft.windowsazure.management.ManagementClient;27import com.microsoft.windowsazure.management.compute.ComputeManagementClient;28import com.microsoft.windowsazure.management.compute.DeploymentSlot;29import com.microsoft.windowsazure.management.compute.models.*;30public class AzureManagerTest {31public static void main(String[] args) throws Exception {32Configuration config = ManagementConfiguration.configure(null, "your subscription id", "your pem file path", "your pem file password", AzureRegion.EAST_US);33ManagementClient managementClient = ManagementClient.create(config);34ComputeManagementClient computeManagementClient = ComputeManagementClient.create(config);35ListHostedServicesResponse response = managementClient.getHostedServicesOperations().listHostedServices();36for (HostedServiceListResponse.HostedService service : response.getHostedServices()) {37System.out.println(service.getServiceName());38}39HostedServiceGetDetailedResponse vm = managementClient.getHostedServicesOperations().getDetailed("your vm name");40System.out.println(vm.getDeployments().get(0).getName());41managementClient.getVirtualMachinesOperations().start("your vm name", "your vm name", DeploymentSlot.Production);

Full Screen

Full Screen

AzureManager

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.azure.AzureManager;2import org.testng.annotations.Test;3import java.io.File;4import java.io.IOException;5import java.util.List;6import java.util.Map;7public class Test1 {8 public void test() throws IOException {9 AzureManager azureManager = new AzureManager();10 List<Map<String, String>> subscriptions = azureManager.getSubscriptions();11 System.out.println(subscriptions);12 List<Map<String, String>> resourceGroups = azureManager.getResourceGroups();13 System.out.println(resourceGroups);14 List<Map<String, String>> virtualMachines = azureManager.getVirtualMachines();15 System.out.println(virtualMachines);16 List<Map<String, String>> virtualMachinesByResourceGroup = azureManager.getVirtualMachinesByResourceGroup("qaprosoft");17 System.out.println(virtualMachinesByResourceGroup);18 List<Map<String, String>> virtualMachinesBySubscription = azureManager.getVirtualMachinesBySubscription("qaprosoft");19 System.out.println(virtualMachinesBySubscription);20 Map<String, String> virtualMachineById = azureManager.getVirtualMachineById("qaprosoft", "qaprosoft", "qaprosoft");21 System.out.println(virtualMachineById);22 Map<String, String> virtualMachineBySubscriptionResourceGroupAndName = azureManager.getVirtualMachineBySubscriptionResourceGroupAndName("qaprosoft", "qaprosoft", "qaprosoft");23 System.out.println(virtualMachineBySubscriptionResourceGroupAndName);24 List<Map<String, String>> virtualMachineSizes = azureManager.getVirtualMachineSizes();25 System.out.println(virtualMachineSizes);26 List<Map<String, String>> virtualMachineSizesBySubscription = azureManager.getVirtualMachineSizesBySubscription("qaprosoft");27 System.out.println(virtualMachineSizesBySubscription);

Full Screen

Full Screen

AzureManager

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.azure.AzureManager;2import java.io.File;3import java.io.IOException;4import java.net.URISyntaxException;5import java.security.InvalidKeyException;6public class 1 {7 public static void main(String[] args) throws IOException, InvalidKeyException, URISyntaxException {8 String storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=;AccountKey=";9 String containerName = "containername";10 String blobName = "blobname";11 File file = new File("path/to/file");12 AzureManager.uploadFile(storageConnectionString, containerName, blobName, file);13 }14}15import com.qaprosoft.azure.AzureManager;16import java.io.IOException;17import java.net.URISyntaxException;18import java.security.InvalidKeyException;19public class 2 {20 public static void main(String[] args) throws IOException, InvalidKeyException, URISyntaxException {21 String storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=;AccountKey=";22 String containerName = "containername";23 String blobName = "blobname";24 AzureManager.downloadFile(storageConnectionString, containerName, blobName, "path/to/file");25 }26}27import com.qaprosoft.azure.AzureManager;28import java.io.IOException;29import java.net.URISyntaxException;30import java.security.InvalidKeyException;31public class 3 {32 public static void main(String[] args) throws IOException, InvalidKeyException, URISyntaxException {33 String storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=;AccountKey=";34 String containerName = "containername";35 String blobName = "blobname";36 AzureManager.deleteFile(storageConnectionString, containerName, blobName);37 }38}39import com.qaprosoft.azure.AzureManager;40import java.io.IOException;41import java.net.URISyntaxException;42import java.security.InvalidKeyException;43public class 4 {44 public static void main(String[] args) throws IOException, InvalidKeyException, URISyntaxException {

Full Screen

Full Screen

AzureManager

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.azure.*;2import com.qaprosoft.azure.*;3public class 1 {4public static void main(String[] args) {5AzureManager manager = new AzureManager();6AzureManager manager = new AzureManager();7}8}9import com.qaprosoft.azure.*;10import com.qaprosoft.azure.*;11public class 2 {12public static void main(String[] args) {13AzureManager manager = new AzureManager();14AzureManager manager = new AzureManager();15}16}17import com.qaprosoft.azure.*;18import com.qaprosoft.azure.*;19public class 3 {20public static void main(String[] args) {21AzureManager manager = new AzureManager();22AzureManager manager = new AzureManager();23}24}25import com.qaprosoft.azure.*;26import com.qaprosoft.azure.*;27public class 4 {28public static void main(String[] args) {29AzureManager manager = new AzureManager();30AzureManager manager = new AzureManager();31}32}33import com.qaprosoft.azure.*;34import com.qaprosoft.azure.*;35public class 5 {36public static void main(String[] args) {37AzureManager manager = new AzureManager();38AzureManager manager = new AzureManager();39}40}41import com.qaprosoft.azure.*;42import com.qaprosoft.azure.*;43public class 6 {44public static void main(String[] args) {45AzureManager manager = new AzureManager();46AzureManager manager = new AzureManager();47}48}

Full Screen

Full Screen

AzureManager

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.azure.*;2import java.io.*;3import java.util.*;4import java.util.concurrent.*;5import java.util.concurrent.atomic.*;6import java.util.concurrent.locks.*;7public class 1 {8 public static void main(String[] args) {9 try {10 AzureManager az = new AzureManager();11 az.createVM("testVM", "testRG");12 az.checkVM("testVM", "testRG");13 az.startVM("testVM", "testRG");14 } catch (Exception e) {15 e.printStackTrace();16 }17 }18}19import com.qaprosoft.azure.*;20import java.io.*;21import java.util.*;22import java.util.concurrent.*;23import java.util.concurrent.atomic.*;24import java.util.concurrent.locks.*;25public class 2 {26 public static void main(String[] args) {27 try {28 AzureManager az = new AzureManager();29 az.stopVM("testVM", "testRG");30 az.checkVM("testVM", "testRG");31 az.deleteVM("testVM", "testRG");32 } catch (Exception e) {33 e.printStackTrace();34 }35 }36}37package com.qaprosoft.azure;38import com.microsoft.azure.management.Azure;39import com.microsoft.azure.management.compute.VirtualMachine;40import com.microsoft.azure.management.compute.VirtualMachineSizeTypes;41import com.microsoft.azure.management.compute.VirtualMachines;42import com.microsoft.azure.management.network.Network;43import com.microsoft.azure.management.network.Networks;44import com.microsoft.azure.management.network.NetworkSecurityGroup;45import com.microsoft.azure.management.network.NetworkSecurityGroups;46import com.microsoft.azure.management.network.NetworkSecurityRule;47import com.microsoft.azure.management.network.PublicIPAddress;48import com.microsoft.azure.management.network.PublicIPAddresses;49import com.microsoft.azure.management.resources.ResourceGroup;50import com.microsoft.azure.management.resources.ResourceGroups;51import com.microsoft.azure.management.resources.fluentcore.arm.Region;52import com.microsoft.azure.management.resources.fl

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Carina automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in AzureManager

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful