While automating testing of a website shopping experience, I am attempting to verify that the subtotal, total, and tax are calculating properly. Since the price and/or tax will change in the future, I cannot simply assert the actual price value inside the control. Instead, I would need to build a calculation based upon the controls themselves and assert that quantity multiplied by individual price for each item added together equals the subtotal, and so on.
For example, say my controls for each are named such (control names are in asterisks):
Quantity = *UIItem2Cell*
(InnerText has a Value of 2)
Individual Price = *UIItem249Pane*
(DisplayText has a value of 2.49)
Individual Product Total (price x qty) = *UIItem498Pane*
(InnerText has a Value of 4.98)
Instead of validating the values are the actual numbers, can I write an assertion formula using the identifiers as variables?
Keep in mind, I am using the Coded UI Test Builder rather than writing the code outright.
If the Individual Product Total InnerText assertion comparator is AreEqual, can the Comparison Value be something like:
UIItem2Cell-InnerText * UIItem249Pane-DisplayText
A. Is this sort of formula possible?
B. If so, how do I write it?
(Please forgive me, as I am very green when it comes to this.)
You most certainly can. First off in your app itself it would be greatly useful to use IDs on your controls so you can match on just that criteria. that way your not using calculated values for search criteria.
Now as is in your question you will need to pull those values from the cells, calculate the Value and use it in your Search Criteria
// I'd recommend trimming text values:
// depending on how tables and such are rendered you'll have extra white-space characters
var firstValue = Double.Parse(UIItem2Cell.InnerText.Trim());
var secondValue = Double.Parse(UIItem249Pane.DisplayText.Trim());
var calculatedValue = string.Format("{0,N2}%", firstValue * secondValue);
// assuming your in a web app
var totalDiv = new HtmlDiv(currentHtmlDoc);
totalDiv.SearchProperties.Add(new PropertyExpression(HtmlDiv.PropertyNames.InnerText, calculatedValue, PropertyExpressionOperator.Contains));
Assert.IsTrue(totalDiv.TryFind());
SringAssert.Contains(totalDiv.InnerText,calculatedValue);
Related
I am working with some weather data that is missing some values (indicated via value code). For example, if SLP data is missing, it is assigned code 99999. I was able to use a window function to calculate a 7 day average and save it as a new column. A significantly reduced example of a single row is shown below:
SLP_ORIGIN
SLP_ORIGIN_7DAY_AVG
99999
11945.823516044207
I'm trying to write code such that when SLP_ORIGIN has the missing code it gets replaced using the SLP_ORIGIN_7DAY_AVG value. However, most code explains how to replace a column value based on a conditional with a constant value, not the column value. I tried using the following:
train_impute = train.withColumn("SLP_ORIGIN", \
when(train["SLP_ORIGIN"] == 99999, train["SLP_ORIGIN_7DAY_AVG"]).otherwise(train["SLP_ORIGIN"]))
where the dataframe is called train.
When I perform a count on the SLP_ORIGIN column using train.where("SLP_ORIGIN = 99999").count() I get the same count from before I attempted replacing the value in that column. I have already checked and my SLP_ORIGIN_7DAY_AVG does not have any values that match the missing code.
So how do I actually replace the 99999 values in the SLP_ORIGIN column with the associated SLP_ORIGIN_7DAY_AVG value?
EVEN BETTER, is there a way to do this replacement and window calculation without making a 7 day average column (I have other variables I need to do the same thing with so I'm hoping there is a more efficient way to do this).
Make sure to double check with dataframe you are verifying on.
I was using train.where("SLP_ORIGIN = 99999").count() when I should have been using train_impute.where("SLP_ORIGIN = 99999").count()
Additionally, instead of making a whole new column to store the imputed 7 day average, one can only calculate the average when the missing value code is present:
train = train.withColumn("SLP_ORIGIN", when(train["SLP_ORIGIN"] == 99999, f.avg('SLP_ORIGIN').over(w)).otherwise(train["SLP_ORIGIN"]))\
I have a 3 fields - all decimal fields:
custbody_myvalue1
custbody_myvalue2
custbody_myvalue3
I need to have custbody_myvalue3 = the sum of custbody_myvalue1 and custbody_myvalue2 via a workflow.
In my workflow I have a formula that sets the value for custbody_myvalue3 whenever either of the 2 other fields are edited:
{custbody_myvalue1}+{custbody_myvalue2}
But this is combining the 2 values - not giving me the sum. If I change the formula to multiply the 2 fields the math works.
What is the proper way to do this in a workflow?
Found the answer. Apparently you need to parse the values in order to sum them.
See SA93584.
Javascript in workflow formula considers "+" operation as adding not
summing and treats a value behind "+" as a string which results in
adding one number behind another, NaN (Not a Number) error or any
other error.
Therefore it is needed to command Javascript to treat a value as a
number. For this purpose can be used only the available functions in
formula builder or SuiteScript functions such as nlapiGetFieldValue.
For instance for the beforehand mentioned arithmetic operations the
following syntax has to be used in order the formula to work properly:
parseFloat(nlapiGetFieldValue('field1') || 0) +
parseFloat(nlapiGetFieldValue('field2') || 0) -
parseFloat(nlapiGetFieldValue('field3') || 0)
I have a project where I need to break people into 3 buckets with task lists that rotate quarterly (Phase A = task list 1, B = task list 2, C = task list 3). The goal here is to sort people into the buckets based on a departure date, with the ideal being that they would depart when they're in the C phase. I have a formula already set up that will tell me the number of quarters between the project start date and the person's departure date, so now I'm trying to figure out how to get Excel to tell me if a person's departure date falls within their bucket's C Phase.
I have this formula in a column called DEROSQtr:=ROUNDDOWN(DAYS360("1-Oct-2020",[#DEROS],FALSE)/90,0)
Now the easy way to approach this would be to build a static array and just see if that formula results in a value in the right array, where the numbers in the array define which quarter from Oct 2020 that the bucket's C Phase is going to be in:
ArrayA = {1;4;7;10;13;16} ArrayB = {2;5;8;11;14;17} ArrayC = {0;3;6;9;12;15}
The formula that pulls this all together is then:
=IF([#EFP]="A",IF(IFNA(MATCH([#DEROSQtr],ArrayA,0),-1)<>-1,TRUE,FALSE),IF([#EFP]="B",IF(IFNA(MATCH([#DEROSQtr],ArrayB,0),-1)<>-1,TRUE,FALSE),IF([#EFP]="C",IF(IFNA(MATCH([#DEROSQtr],ArrayC,0),-1)<>-1,TRUE,FALSE),"-")))
Now while this will work for as long as I build out the static array, I'm trying to figure out how to define each of these buckets with a formula that Excel can work with, i.e. bucket A hits phase C in 3n + 1 quarters where n is the number of cycles through all 3 phases, so ArrayA = 3n+1, ArrayB = 3n+2 and ArrayC = 3n. What I'm hunting for here is the best way to define each of the arrays as a formula.
After some additional digging and looking back at how to define each array, I came across the MOD() function in Excel. I was then able to rewrite the formula that does the checking as =IF([#EFP]="A",IF(MOD([#DEROSQtr]-1,3)=0,TRUE,FALSE),IF([#EFP]="B",IF(MOD([#DEROSQtr]-2,3)=0,TRUE,FALSE),IF([#EFP]="C",IF(MOD([#DEROSQtr],3)=0,TRUE,FALSE),"-"))), replacing ArrayA(3n+1) with MOD([#DEROSQtr]-1,3), ArrayB(3n+2) with MOD([#DEROSQtr]-2,3), and ArrayC(3n) with MOD([#DEROSQtr],3).
Since I do not have the data you are calculating your quarter, its difficult to give you exact answer. However, as I understand your have a column which has the formula to calculate the quarter say "Formula_Col"
Solution will be to add a new column and flag it based on the values in "Formula_Col".
If you can give some sample data I can provide exact answer.
I'm using SUMIFS function to compute commissions based on invoice data. One of the fields I need to check has a product code with many meanings based on position of the data within the code.
For example, product code of "NCH - R - OTF - CH" indicates owner of product is NCH, R meaning Retail, OTF meaning Off the Shelf, and CH meaning commission on Chinese Herbs.
I need to add additional condition in my current SUMIFs function to check if the product code in column āDā has commission code of "CH". I need to only check the last two characters of the product item code.
=SUMIFS('Invoice Items'!$M$2:$M$30000,'Invoice Items'!$F$2:$F$30000,"Product",'Invoice Items'!$A$2:$A$30000,"=Paid")
You can add
'Invoice Items'!$D$2:$D$30000, "*CH"
as a set of criteria to SUMIFS
it will look like:
=SUMIFS('Invoice Items'!$M$2:$M$30000,'Invoice Items'!$F$2:$F$30000,"Product",'Invoice Items'!$A$2:$A$30000,"=Paid",'Invoice Items'!$D$2:$D$30000, "*CH")
I'm making a spreadsheet in excel to help me understand how starting a part-time business on top of my full time job might affect my tax. I need to do this because I'm very close to my next UK tax bracket and I want to know exactly how it might affect my finances.
As part of this I'm trying to write an excel formula that will add two numbers then check if this new number is greater than a third number. I will refer to the two numbers added together as A and the third number as B. If A is not greater than B then I will multiply by 20% to find out how much of it is owed in tax. If A is greater than B I will subtract B from A to create number C and multiply B by 20% and C by 40% and add the two together to produce the final number I need. Can someone please xplain to me how to script this in Excel? I've looked for online examples but I'm not finding the language very penetrable. If I was using a scripting language I was more familiar with the code would look like this:
float taxThreshold = 42011.00;
int income = foo;
if(taxThreshold < income)
{
float higherRate = income-taxThreshold;
float standardTaxOwed = taxThreshold * 20%;
float higherRateOwed = higherRate * 40%;
float finalTaxOwed = standardTaxOwed+higherTaxOwed;
}
else
{
float finalTaxOwed = income * 20%;
}
I'm sure this is very simple to do, I just don't get the excel syntax. Can someone show me how this should be done? You'd not only be solving this problem but also giving me a means of translating from my current scripting knowledge into excel.
The easiest way is to store your 4 input parameters in some cells - and then name them. To do so, select the cell and type a meaningful name into the field that shows the address (i.e. left of the formula bar).
Once you have done this, you can simply use this formula:
=IF(Income>Threshold,Threshold*StandardTaxRate+(Income-Threshold)*HighTaxRate,Income*StandardTaxRate)
Without the naming, the formula would be something like this:
=IF(B2>B1,B1*B7+(B2-B1)*B8,B2*B7)
Both formulas will calculate you the tax you'd need to pay. If you want it more explicit, I'd recommend a layout such as this:
The formulas would read:
C7: =IF(B2>B1,B1,B2)
C8: =IF(B2>B1,B2-B1,0)
D7: =B7*C7
D8: =B8*C8
HTH!