Appium Basic UI Check Cases_from sample

Source: Internet
Author: User
Tags gettext gety xpath appium

@Test

public void Testuicomputation () throws Exception {

Populate text fields with values

Populate ();

Trigger computation by using the button

Click the control to calculate the two-digit and

Webelement button = driver.findelement (By.classname ("Uiabutton"));

Button.Click ();

is sum equal?

Judging whether the obtained number is the correct and equal

Webelement texts = driver.findelement (By.classname ("Uiastatictext"));

Assertequals (string.valueof (values.get (0) + values.get (1)), Texts.gettext ());

}

@Test

public void Testbasicalert () throws Exception {

//Click the alert control, pop up the prompt box

Driver.findelement (By.xpath ("//uiabutton[2]"). Click ();

Alert alert = Driver.switchto (). alert ();

Check if title of alert is correct

Verify that the text of the prompt box is correct

Assertequals ("Cool title this alert was so Cool.", Alert.gettext ());

Alert.accept ();

}

@Test

public void Testbasicbutton () throws Exception {

//Verify that the Sum button text is displayed correctly

Webelement button = driver.findelement (By.xpath ("//uiabutton[1]"));

Assertequals ("Compute Sum", Button.gettext ());

}

@Test

public void Testclear () throws Exception {

//Verify that the edit box entry is empty after the edit box content is blank

Webelement Text = driver.findelement (By.xpath ("//uiatextfield[1]"));

Text.sendkeys ("12");

Text.clear ();

Assertequals ("", Text.gettext ());

}

@Test

public void Testhidekeyboard () throws Exception {

//edit box Enter text

Driver.findelement (By.xpath ("//uiatextfield[1]")). SendKeys ("12");

Confirm if the keyboard pops up

Webelement button = driver.findelement (Mobileby.accessibilityid ("Done"));

Asserttrue (button.isdisplayed ());

Click the Hide keyboard

Button.Click ();

}

@Test

public void Testfindelementbyclassname () throws Exception {

Random random = new random ();

Testing with classname positioning controls

Webelement Text = driver.findelementbyclassname ("Uiatextfield");

int number = Random.nextint (maximum-minimum + 1) + MINIMUM;

Text.sendkeys (string.valueof (number));

Driver.findelementbyclassname ("Uiabutton"). Click ();

is sum equal?

Verify that they are equal

Webelement Sumlabel = Driver.findelementbyclassname ("Uiastatictext");

Assertequals (string.valueof (number), Sumlabel.gettext ());

}

@Test

public void Testfindelementsbyclassname () throws Exception {

Random random = new random ();

Testing with classname positioning controls

Webelement Text = (webelement) driver.findelementsbyclassname ("Uiatextfield"). Get (1);

int number = Random.nextint (maximum-minimum + 1) + MINIMUM;

Text.sendkeys (string.valueof (number));

Driver.findelementbyclassname ("Uiabutton"). Click ();

is sum equal?

Webelement Sumlabel = (webelement) driver.findelementsbyclassname ("Uiastatictext"). Get (0);

Assertequals (string.valueof (number), Sumlabel.gettext ());

}

@Test

public void Testattribute () throws Exception {

Random random = new random ();

Webelement Text = driver.findelement (By.xpath ("//uiatextfield[1]"));

edit box Enter text

int number = Random.nextint (maximum-minimum + 1) + MINIMUM;

Text.sendkeys (string.valueof (number));

Verify that properties such as the control's name,label,value are the same as the settings, and name is Integera

Assertequals ("Integera", Text.getattribute ("name"));

Assertequals ("TextField1", Text.getattribute ("label"));

Assertequals (string.valueof (number), Text.getattribute ("value"));

}

@Test

public void Testslider () throws Exception {

Get the Slider

//progress bar control

Webelement slider = driver.findelement (By.xpath ("//uiaslider[1]");

See if the initial data is 50%

Assertequals ("50%", Slider.getattribute ("value"));

Point sliderlocation = Getcenter (slider);

Drag controls, drag from center to initial position

Driver.swipe (Sliderlocation.getx (), Sliderlocation.gety (), Sliderlocation.getx () -100, Sliderlocation.gety (), 1000) ;

Verify that the control is returned to 0, not 0?

Assertequals ("0%", Slider.getattribute ("value"));

}

@Test

public void Testlocation () throws Exception {

//Verify the location of the control is 94,122?

Webelement button = driver.findelement (By.xpath ("//uiabutton[1]"));

Point location = Button.getlocation ();

Assertequals (94, Location.getx ());

Assertequals (142, location.gety ());

}

@Test

public void Testsessions () throws Exception {

// ?

HttpGet request = new HttpGet ("Http://localhost:4723/wd/hub/sessions");

@SuppressWarnings ("resource")

HttpClient HttpClient = new Defaulthttpclient ();

HttpResponse response = Httpclient.execute (request);

httpentity entity = response.getentity ();

Jsonobject Jsonobject = (jsonobject) new Jsonparser (). Parse (entityutils.tostring (entity));

String sessionId = Driver.getsessionid (). toString ();

Assertequals (Jsonobject.get ("SessionId"), sessionId);

}

@Test

public void Testsize () {

//Verify that the two edit box controls are of the same size

Dimension Text1 = driver.findelement (By.xpath ("//uiatextfield[1]"). GetSize ();

Dimension Text2 = driver.findelement (By.xpath ("//uiatextfield[2]"). GetSize ();

Assertequals (Text1.getwidth (), Text2.getwidth ());

Assertequals (Text1.getheight (), Text2.getheight ());

}

Appium Basic UI Check Cases_from sample

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.