com.ats.script.actions.ActionWindowSwitch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ats-automated-testing Show documentation
Show all versions of ats-automated-testing Show documentation
Code generator library to create and execute GUI automated tests
The newest version!
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package com.ats.script.actions;
import java.util.ArrayList;
import com.ats.executor.ActionTestScript;
import com.ats.executor.channels.Channel;
import com.ats.generator.objects.TryAndDelay;
import com.ats.generator.variables.CalculatedValue;
import com.ats.script.Script;
import com.ats.tools.Utils;
import com.ats.tools.logger.ExecutionLogger;
import com.google.gson.JsonObject;
public class ActionWindowSwitch extends ActionWindow implements IActionStoppable{
public static final String SCRIPT_SWITCH_LABEL = SCRIPT_LABEL + "switch";
public static final String REFRESH_AFTER_SWITCH = "refresh";
// private int num = 0;
private CalculatedValue num = new CalculatedValue(0);
private int tries = 0;
private int delay = 0;
private boolean refresh = false;
public ActionWindowSwitch() {}
public ActionWindowSwitch(Script script, CalculatedValue num, ArrayList options) {
super(script);
final int[] data = TryAndDelay.getTryAndDelay(options);
setNum(num);
setTries(data[0]);
setDelay(data[1]);
setRefresh(options.stream().anyMatch(str -> str.trim().contains(REFRESH_AFTER_SWITCH)));
}
public ActionWindowSwitch(Script script, int tries, CalculatedValue num, int delay, boolean refresh) {
super(script);
setNum(num);
setTries(tries);
setDelay(delay);
setRefresh(refresh);
}
@Override
public StringBuilder getJavaCode() {
return super.getJavaCode().append(tries).append(", ").append(num.getJavaCode()).append(", ").append(delay).append(", ").append(refresh).append(")");
}
@Override
public String execute(ActionTestScript ts, String testName, int testLine, int tryNum) {
super.execute(ts,testName,testLine, tryNum);
return null;
}
@Override
public String exec(Channel channel, ExecutionLogger logger) {
int numInt = Utils.string2Int(num.getCalculated());
channel.switchWindow(status, numInt, tries, delay, refresh);
return String.valueOf(numInt);
}
@Override
public StringBuilder getActionLogs(String scriptName, int scriptLine, JsonObject data) {
data.addProperty("index", num.getCalculated());
data.addProperty("tries", tries);
data.addProperty("refresh", refresh);
return super.getActionLogs(scriptName, scriptLine, data);
}
@Override
public boolean isStop() {
return true;
}
//--------------------------------------------------------
// getters and setters for serialization
//--------------------------------------------------------
public int getDelay() {
return delay;
}
public void setDelay(int delay) {
this.delay = delay;
}
public boolean isRefresh() {
return refresh;
}
public void setRefresh(boolean refresh) {
this.refresh = refresh;
}
public CalculatedValue getNum() {
return num;
}
public void setNum(CalculatedValue num) {
this.num = num;
}
public int getTries() {
return tries;
}
public void setTries(int tries) {
this.tries = tries;
}
public static StringBuilder getAtsCodeStr() {
return new StringBuilder().append(SCRIPT_LABEL).append(" -> ");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy