Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is a demo TestComplete test written in JavaScript to test BMI Calculator native iOS app with Appium
function BmiCalculatorTest()
{
try
{
//Create an instance of DesirecCapabilities, CapabilityType and By Class using CLR Bridge & dotNET Object
var Capabilities = dotNET.OpenQA_Selenium_Remote.DesiredCapabilities.zctor();
var CapabilityType = dotNET.OpenQA_Selenium_Remote.CapabilityType;
var By = dotNET.OpenQA_Selenium.By;
//Set up the capabilities to run test on iOS application on local Appium server
Capabilities.setCapability(CapabilityType.BrowserName, "iOS");
Capabilities.setCapability(CapabilityType.Version, "6.1");
Capabilities.setCapability(CapabilityType.Platform, "Mac");
//Set up the RemoteWebDriver
var uri = dotNET.System.Uri.zctor("http://mymacmachine:4723/wd/hub");
var driver = dotNET.OpenQA_Selenium_Remote.RemoteWebDriver.zctor_3(uri,Capabilities);
//Get the Hight text field and enter value
var HeightField = driver.FindElement(By.Name("Height"));
HeightField.SendKeys("181");
//Get the Weight text field and enter value
var WeightField = driver.FindElement(By.Name("Weight"));
WeightField.SendKeys("80");
//Get the Calculate button and tap/click on it
var CalculateButton = driver.FindElement(By.Name("Calculate"));
CalculateButton.Click();
//Get the Bmi lables
var BmiLabel = driver.FindElement(By.Name("bmi"));
var BmiCategoryLabel = driver.FindElement(By.Name("category"));
//Check labels for expected values
if(aqObject.CompareProperty(BmiLabel.Text, cmpEqual, "24.42")) {
Log.Checkpoint ("Calculated BMI is correct!");
}
else {
Log.Error( "Calculated BMI does not match expected value");
}
if(aqObject.CompareProperty(BmiCategoryLabel.Text, cmpEqual, "Normal")) {
Log.Checkpoint( "BMI Category is correct!");
}
else {
Log.Error( "BMI Category does not match with expected value");
}
driver.Quit();
}
catch(err){
Log.Error(err.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment