Пример #1
0
// FlickFinger performs a flick touch action by the provided offset and at the
// provided speed on exactly one element.
func (s *Selection) FlickFinger(xOffset, yOffset int, speed uint) error {
	selectedElement, err := s.elements.GetExactlyOne()
	if err != nil {
		return fmt.Errorf("failed to select element from %s: %s", s, err)
	}

	if err := s.session.TouchFlick(selectedElement.(*api.Element), api.XYOffset{X: xOffset, Y: yOffset}, api.ScalarSpeed(speed)); err != nil {
		return fmt.Errorf("failed to flick finger on %s: %s", s, err)
	}
	return nil
}
Пример #2
0
		})
	})

	Describe("#FlickFinger", func() {
		var firstElement *api.Element

		BeforeEach(func() {
			firstElement = &api.Element{}
			elementRepository.GetExactlyOneCall.ReturnElement = firstElement
		})

		It("should successfully flick on the selected element", func() {
			Expect(selection.FlickFinger(100, 200, 300)).To(Succeed())
			Expect(session.TouchFlickCall.Element).To(ExactlyEqual(firstElement))
			Expect(session.TouchFlickCall.Offset).To(Equal(api.XYOffset{X: 100, Y: 200}))
			Expect(session.TouchFlickCall.Speed).To(Equal(api.ScalarSpeed(300)))
		})

		Context("when exactly one element is not returned", func() {
			It("should return an error", func() {
				elementRepository.GetExactlyOneCall.Err = errors.New("some error")
				Expect(selection.FlickFinger(100, 200, 300)).To(MatchError("failed to select element from selection 'CSS: #selector': some error"))
			})
		})

		Context("when the flick fails", func() {
			It("should return an error", func() {
				session.TouchFlickCall.Err = errors.New("some error")
				Expect(selection.FlickFinger(100, 200, 300)).To(MatchError("failed to flick finger on selection 'CSS: #selector': some error"))
			})
		})