← Back to team overview

sikuli-driver team mailing list archive

[Question #273328]: Alternative to multiple If Else statements

 

New question #273328 on Sikuli:
https://answers.launchpad.net/sikuli/+question/273328

Hello,

I am writing a test script for  a UI in Java using Sikuli and TestNG plugin in the Eclipse IDE.  This is one of many test classes I am calling from a testng.xml file.  I am looking for an alternative or shorter version of the following code specifically the If Else part.

public class createNewRun {

@Test (groups="createNewRun", dependsOnMethods="launchDUT")
	public createNewRun() throws InterruptedException, FindFailed {
		Screen s = new Screen();
		try {
			s.click(s.wait("img/Home.png", 10));
			s.click(s.wait("img/Begin.png", 10));
			s.click(s.wait("img/CreateNewRun.png", 5));
			s.click(s.wait("img/NewConfiguration.png", 5));
			s.click(s.wait("img/ConfigurationName.png", 5));
			s.type("AR");
			Pattern pimage = new Pattern("img/AR Test.png").targetOffset(-60,-1);
			Match r  = s.exists(pimage,1);
			s.click(r,0);
			s.click(s.wait("img/Save.png", 5));
			s.click(s.wait("img/Begin-1.png"));
			s.click(s.wait("img/Play.png"));

                       if (s.exists("img/Submit.png",5) != null) {

				s.click(s.wait("img/Submit.png"));
			}
			else {
				s.click(s.wait("img/Play.png",5));
			}
			if (s.exists("img/Submit.png",5) != null) {

				s.click(s.wait("img/Submit.png"));
			}
			else {
				s.click(s.wait("img/Play.png",5));
			}
			if (s.exists("img/Submit.png",5) != null) {

				s.click(s.wait("img/Submit.png",5));
			}
			else {
			        s.click(s.wait("img/Play.png",5));

		     }
		}
		catch(FindFailed e){
			e.printStackTrace();
		}
	}

}


Does anyone have suggestions for how I can accomplish this without having to repeat the "If" "Else" so many times?  Thanks in advance!

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.