public void BeforeTest() { AppiumOptions capabilities = new AppiumOptions(); // 1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com). String cloudName = "<<cloud name>>"; // 2. Replace <<security token>> with your perfecto security token. String securityToken = "<<security token>>"; capabilities.AddAdditionalCapability("securityToken", securityToken); // 3. Set device capabilities. capabilities.PlatformName = "Android"; capabilities.AddAdditionalCapability("model", "Galaxy S.*|LG.*"); // 4. Set Perfecto Media repository path of App under test. capabilities.AddAdditionalCapability("app", "PUBLIC:ExpenseTracker/Native/android/ExpenseAppVer1.0.apk"); // 5. Set the unique identifier of your app capabilities.AddAdditionalCapability("appPackage", "io.perfecto.expense.tracker"); // Set other capabilities. capabilities.AddAdditionalCapability("enableAppiumBehavior", true); capabilities.AddAdditionalCapability("autoLaunch", true); // Whether to install and launch the app automatically. // capabilities.AddAdditionalCapability("fullReset", false); // Reset app state by uninstalling app. capabilities.AddAdditionalCapability("takesScreenshot", false); capabilities.AddAdditionalCapability("screenshotOnError", true); capabilities.AddAdditionalCapability("openDeviceTimeout", 5); capabilities.AddAdditionalCapability("model", "Galaxy S.*"); // Initialize the Appium driver driver = new AndroidDriver <AndroidElement>( new Uri(string.Format("https://{0}.perfectomobile.com/nexperience/perfectomobile/wd/hub/fast", cloudName)), capabilities); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); PerfectoExecutionContext perfectoExecutionContext; if (System.Environment.GetEnvironmentVariable("jobName") != null) { perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder() .WithProject(new Project("My Project", "1.0")) .WithJob(new Job(System.Environment.GetEnvironmentVariable("jobName"), int.Parse(System.Environment.GetEnvironmentVariable("jobNumber")))) .WithWebDriver(driver).Build(); } else { perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder() .WithProject(new Project("My Project", "1.0")) .WithWebDriver(driver).Build(); } reportiumClient = PerfectoClientFactory.CreatePerfectoReportiumClient(perfectoExecutionContext); reportiumClient.TestStart(TestContext.TestName, new Reportium.Test.TestContext("native", "android")); }
public void RemoteWebDriverExtendedTest() { //Starting a test with the following context tags. reportiumClient.TestStart("Reportium C# Test should success", new ReportiumTestContext("test 1", "c#", "should success")); reportiumClient.TestStep("Navigate to google and search PerfectoCode GitHub"); //Test step will be shown on the report ui driver.Navigate().GoToUrl("https://www.google.com"); //locate the search bar and sendkeys driver.FindElementByName("q").SendKeys("PerfectoCode GitHub"); //click on the search button driver.FindElementByXPath("//*[@aria-label='Google Search']").Click(); reportiumClient.TestStep("Choose first result and validate title"); //Add as many test steps as you want // driver.FindElementByCssSelector("#rso > div > div:nth-child(1) > div > div > div._OXf > h3 > a").Click(); var keyword = "Perfecto"; //a keyword to validate Assert.IsTrue(driver.FindElementByPartialLinkText(keyword).Displayed); //assert that Keyword is in the page title // Assert.IsTrue(driver.Title.Contains(keyword)); }
public void AndroidTest() { DesiredCapabilities capabilities = new DesiredCapabilities(); // 1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com). String cloudName = "<<cloud name>>"; // 2. Replace <<security token>> with your perfecto security token. String securityToken = "<<security token>>"; capabilities.SetCapability("securityToken", securityToken); // 3. Set web capabilities. capabilities.SetCapability("platformName", "Android"); capabilities.SetCapability("model", "Galaxy S.*"); capabilities.SetCapability("browserName", "Chrome"); capabilities.SetCapability("useAppiumForWeb", true); capabilities.SetCapability("openDeviceTimeout", 5); // Initialize the driver RemoteWebDriver driver = new RemoteWebDriver( new Uri("https://" + cloudName.Replace(".perfectomobile.com", "") + ".perfectomobile.com/nexperience/perfectomobile/wd/hub"), capabilities); // Setting implicit wait driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); PerfectoExecutionContext perfectoExecutionContext; if (System.Environment.GetEnvironmentVariable("jobName") != null) { perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder() .WithProject(new Project("My Project", "1.0")) .WithJob(new Job(System.Environment.GetEnvironmentVariable("jobName"), int.Parse(System.Environment.GetEnvironmentVariable("jobNumber")))) .WithWebDriver(driver).Build(); } else { perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder() .WithProject(new Project("My Project", "1.0")) .WithWebDriver(driver).Build(); } ReportiumClient reportiumClient = PerfectoClientFactory.CreatePerfectoReportiumClient(perfectoExecutionContext); reportiumClient.TestStart("Selenium C# Android Sample", new Reportium.Test.TestContext("selenium", "android")); try { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); String search = "perfectomobile"; reportiumClient.StepStart("Navigate to Google"); Dictionary <String, Object> pars = new Dictionary <String, Object>(); driver.Url = "https://www.google.com"; reportiumClient.StepEnd(); reportiumClient.StepStart("Search for Perfecto"); IWebElement searchbox = wait.Until(ExpectedConditions.ElementToBeClickable(driver.FindElement(By.XPath("//*[@name='q']")))); searchbox.SendKeys(search); searchbox.SendKeys(Keys.Enter); reportiumClient.StepEnd(); reportiumClient.StepStart("Verify Title"); String expectedText = "perfectomobile - Google Search"; Console.WriteLine(driver.Title); // Adding assertions to the Execution Report. This method will not fail the test reportiumClient.ReportiumAssert(expectedText, driver.Title.Contains(expectedText)); reportiumClient.StepEnd(); reportiumClient.TestStop(TestResultFactory.CreateSuccess()); } catch (Exception e) { reportiumClient.TestStop(TestResultFactory.CreateFailure(e)); } // Prints the Smart Reporting URL String reportURL = reportiumClient.GetReportUrl(); Console.WriteLine("Report url - " + reportURL); // Quits the driver driver.Quit(); }
public static void beforeScenario() { reportingClient.TestStart(ScenarioContext.Current.ScenarioInfo.Title, new TestContext(ScenarioContext.Current.ScenarioInfo.Tags)); }
public void SetUp() { //Start a new reporting for the test with the full test name reportiumClient.TestStart(NTestContext.CurrentContext.Test.FullName, new TestContext("My First NUnit test", "Tag1", "Tag2")); }