I am trying to implement below move_to action
https://www.rubydoc.info/gems/appium_lib/9.3.8/Appium%2FTouchAction:move_to
Appium::TouchAction.new.press(x: 176, y: 200).move_to(50).perform
but it is giving error
NoMethodError:
undefined method `key?' for 100:Integer
I want to move/swipe screen on iOS Simulator from one co-ordinates to other co-ordinates.
The link you posted clearly states that move_to expects a hash with :x and :y as parameters, just like you passed to press.
Appium::TouchAction.new.press(x: 176, y: 200).move_to(x: 176, y: 200).perform
The syntax for TouchAction is as follows (in python):
touch = TouchAction(driver)
touch.press(x=473, y=1396).move_to(x=468, y=705).release().perform()
The syntax remains the same for ruby with paramenters for press and move_to class
Related
I am trying to write a test for scrolling down on both iOS and Android. Currently focusing on Android.
The issue is that I can click on things but I don't know how to scroll.
I've tried implementing this code to begin with. (line 17 to 28)
When I paste it as it is I get this error:
undefined local variable or method `driver' for #Object+RSpec::Matchers+Cucumber::Glue::ProtoWorld+#<Module:0x0000004008b49bd0+PP::ObjectMixin+JSON::Ext::Generator::GeneratorMethods::Object+Kernel+:0xd070> (NameError)
When I remove driver and insert $app instead the code looks like this:
When('I scroll down') do
window = $app.window_rect
action_builder = $app.action
input = action_builder.pointer_inputs[0]
action_builder
.move_to_location(window.width / 2, window.height * 8 / 10)
.pointer_down(:left)
.pause(device: input, duration: 1)
.move_to_location(window.width / 2, window.height / 10)
.pause(device: input, duration: 1)
.release
.perform
end
This is the error I get:
undefined method `window_rect' for #AndroidApp:0x0000004006957248
window = $app.window_rect
^^^^^^^^^^^^ (NoMethodError)
I tried to remove the line: window = $app.window_rect, and this is the new error:
undefined method `action' for #AndroidApp:0x000000400694fe58
action_builder = $app.action
^^^^^^^ (NoMethodError)
This part works fine:
(In the android support file)
def navigation_podcast_tab
$driver.find_element(:id, ID_PREFIX + "navigation_item_podcast")
end
(In the iOS support file)
def navigation_podcast_tab
$driver.find_element(:name, "Podcasts")
end
(The scenario step)
When("I go to the podcast tab") do
$wait.until { $app.navigation_podcast_tab.displayed? }
$app.navigation_podcast_tab.click
end
My question is how do I use the action builder to perform swipes, scrolls etc.?
I have a text object in ruby 2D showing score. How do I update the text?
I have this so far
update do
text = Text.new("Score: #{#score}")
end
Instead of replacing it, it is creating a new text object on top of it. How could you replace it instead of adding it on?
Based on docs it seems like you need to instantiate the Text object outside of the update loop. This will draw it to the screen "forever" until you call the remove method.
In your current code you are just instantiating a new object every time, and Ruby 2D is secretly keeping it around even though you don't have it assigned to a variable.
Unlike some other 2D libraries like Gosu, Ruby 2D does not stop drawing something until you explicitly tell it to.
Try
#text = Text.new("Score: #{#score}")
update do
...
#text.remove # At a time you want to stop displaying that text.
...
end
Adding and removing objects in Ruby 2D
here a simple example how to use the Text class in ruby2d
require 'ruby2d'
sector = 3
txt = Text.new(
sector.to_s,
x: 10, y: 10,
size: 20,
color: 'white',
z: 10
)
on :key_down do |event|
case event.key
when 'a'
sector += 1
txt.text = sector.to_s
when 's'
sector -= 1
txt.text = sector.to_s
end
end
show
I do a first simple tkinter tool. It connects via FTP to a server and uploads a file (it's for a restaurant's menucard to go on their server).
All this is working fine.
I'm trying to make an animation indicating the upload. And there is a problem.
The main-class inherits from Tk
inits menu, buttons and such, relevant: self.anim = Canvas(self, width=500, height=300) # Canvas for Animation
self.anim.grid(column=0, row=5)
eventually, when uploading it calls self.animation()
There I draw a little PC via create_... methods and then what should be the card, zooming out the screen and going up. Running I see like maybe 4 of 5 runs how it is supposed to show up (so far) but sometimes it looks like it renders that animations two times (second double in factor) and these are overlapping, zooming twice as big and going far out of intended stop...
That's not a good sign, same input, different output. Anyone can explain why this happens?
x0, y0, x1, y1 = (185, 100, 190, 110) # menucard
ix0, iy0, ix1, iy1 = (187, 102, 189, 104) # menucard's "image"
self.speisekarte = self.anim.create_rectangle(x0, y0, x1, y1, # menucard
outline='#bbb', fill='#fef',
stipple='gray75', tag='karte')
self.karteimg = self.anim.create_rectangle(ix0, iy0, ix1, iy1, # menucard's "image"
outline='#f77', fill='#f57',
stipple='gray50', tag='karte')
self.anim.create_line(185, 100, 185, 109, tag='karte')
self.anim.update()
for z in range(13):
self.anim.after(100, self.zoom())
for z in range(50):
self.anim.after(50, self.move())
self.anim.create_text(350, 50, text='O N L I N E !', fill='#f57')
def zoom(self):
self.anim.scale('karte', 185, 110, 1.09, 1.06)
self.anim.update()
def move(self):
self.anim.move('karte', 2, -1)
self.anim.update()
#furas helped me to my solution. From there I had to find a way to exit the function. I found nowwhere an example, so here how it works for me now:
def animdrawUpload(self):
while self.move():
pass
return True
def move(self):
if self.anim.coords('karte')[0] > 300:
return False
self.anim.move('karte', 2, -1)
self.anim.update()
self.anim.after(100, self.move)
return True
Eventually I just have to hope I will get the same result on windows10 ;)
My version of Python is 3.2, and Pygame is 1.9.1.
I followed the first part of the instructions found here: http://wiki.sheep.art.pl/Tiled%20Map%20in%20PyGame, with a few adjustments to accommodate for my own tileset:
def load_tileset(filename, width, height):
image = pygame.image.load(filename).convert_alpha()
imageWidth, imageHeight = image.get_size()
tileSet = []
for tileX in range(0, 3):
line = []
tileSet.append(line)
for tileY in range(0, 3):
rect = (tileX*width, tileY*height, width, height)
line.append(image.subsurface(rect))
if __name__=='__main__':
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Tiled Background')
screen.fill((240, 240, 255))
table = load_tileset('tableset.gif', 16, 16)
for x, row in enumerate(table):
for y, tile in enumerate(row):
screen.blit(tile, (x*24, y*24))
pygame.display.flip()
while pygame.event.wait().type != pygame.locals.QUIT:
pass
I get the Nonetype error in for x, row in enumerate(table):*. I've tried various things, even moving the tileset itself, and changing the file type. I've also tried other codes, such as range.
I have managed to load images in the past, this is just my first time trying to use a tile set. The tile set has 9 16x16 tiles, and there is some transparency in them (hence the convert_alpha()).
So, can anyone say why I got the NoneType error here? Is it something to do with the image?
(Note, the reason there's 3's in the "For tileX in range" is that it wouldn't accept the calculation as set fourth in the tutorial, so I just did the maths myself.)
Edit: Accidently typed: for x, row in range(table): instead of for x, row in enumerate(table): in description.
You aren't posting the full code, or have made a mistake: there's no for x, row in range(table) line in the code above. With this specific code, you seem to be trying to pull two variables from the range function, but it only returns one value at a time.
You probably meant to type for x, row in enumerate(table). In that case, you need to return an object when you call table = load_tileset('tableset.gif', 16, 16) because unless any given function is explicitly told to return an object, it'll return None and that's why the line is giving you trouble, because the type of None is Nonetype
Here's an example of a function returning None and then returning a string, a returned string:
def thisFuncReturnsNone():
pass
print 'what gets returned:', thisFuncReturnsNone()
>>> None
def thisFuncReturnsAString():
return 'a returned string'
print 'what gets returned a second time:', thisFuncReturnsAString()
>>> a returned string
Now I made WidgetArea originally for Windows, but being primarily a Linux user. I wanted to make it for Linux as well, but mainly to learn more about the file dialog in PyGTK. So I took a look at this tutorial to have a better understanding of it, while working on this simple, yet small application, as that's easier for me to learn, and understand by experimentation.
So here's my source code.
#!/usr/bin/env python
import sys, os
import pygtk, gtk, gobject
import pygst
pygst.require("0.10")
import gst
class WidgetArea(gtk.Window):
def addwidget(self, w):
self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.win.set_title("Widget")
self.win.set_decorated(False)
self.win.set_has_frame(False)
self.win.set_resizable(False)
self.win.set_keep_above(True)
self.win.set_property('skip-taskbar-hint', True)
self.previewimage = gtk.Image()
self.win.add(self.previewimage)
self.win.show_all()
def pinning(self, checkbox):
if checkbox.get_active():
self.set_keep_above(True)
else:
self.set_keep_above(False)
def change_size(self, w):
width = int(self.entryw.get_text())
height = int(self.entryh.get_text())
self.win.set_size_request(width,height)
def __init__(self):
super(WidgetArea, self).__init__()
self.set_position(gtk.WIN_POS_CENTER)
self.set_title("WidgetArea")
self.set_resizable(False)
self.set_keep_above(True)
self.set_property('skip-taskbar-hint', True)
self.connect("destroy", gtk.main_quit, "WM destroy")
vbox = gtk.VBox(spacing=0)
hbox = gtk.HBox(spacing=0)
hbox2 = gtk.HBox(spacing=0)
hbox3 = gtk.HBox(spacing=0)
hbox4 = gtk.HBox(spacing=0)
self.widgetsize = gtk.Label("Widget Size:")
self.widgetsize.set_size_request(100, 30)
self.entryw = gtk.Entry()
self.entryh = gtk.Entry()
self.entryw.set_text("270")
self.entryw.set_size_request(75, 30)
labelcoma = gtk.Label(",")
labelcoma.set_size_request(10, 30)
self.entryh.set_text("221")
self.entryh.set_size_request(75, 30)
labelspac1 = gtk.Label(" ")
labelspac1.set_size_request(10, 30)
hbox.pack_start(self.widgetsize)
hbox.pack_start(self.entryw)
hbox.pack_start(labelcoma)
hbox.pack_start(self.entryh)
hbox.pack_start(labelspac1, 0, 0, 10)
check = gtk.CheckButton("Pin This Window")
check.set_active(True)
check.connect("clicked", self.pinning)
hbox.pack_start(check, 0, 0, 10)
labelspac2 = gtk.Label(" ")
labelspac2.set_size_request(250, 15)
hbox2.pack_start(labelspac2)
filefilter = gtk.FileFilter()
filefilter.set_name("Images")
filefilter.add_mime_type("image/png")
filefilter.add_mime_type("image/jpeg")
filefilter.add_mime_type("image/gif")
filefilter.add_mime_type("image/tiff")
filefilter.add_mime_type("image/svg+xml")
filefilter.add_pattern("*.jpg")
self.ref_file_button = gtk.FileChooserButton('Add Widget')
self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"]))
self.ref_file_button.set_filter(filefilter)
self.ref_file_button.connect("file-set", self.on_open_clicked)
hbox3.pack_start(self.ref_file_button, 150, 150, 10)
labelspac5 = gtk.Label(" ")
labelspac5.set_size_request(0, 10)
hbox4.pack_start(labelspac5)
vbox.pack_start(hbox)
vbox.pack_start(hbox2)
vbox.pack_start(hbox3)
vbox.pack_start(hbox4)
self.add(vbox)
self.show_all()
def on_open_clicked(self, widget, data=None):
ref_image_path = widget.get_filename()
self.previewimage.set_from_file(ref_image_path)
self.addwidg.connect("clicked", self.addwidget)
self.addwidg.connect("clicked", self.change_size)
ref_image_path.destroy()
WidgetArea()
gtk.gdk.threads_init()
gtk.main()
I removed the following code (1st), due to the following error (2nd).
self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"]))
Traceback (most recent call last):
File "./widgetarea.py", line 109, in <module>
WidgetArea()
File "./widgetarea.py", line 86, in __init__
self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"]))
AttributeError: 'WidgetArea' object has no attribute 'rootdir'
Now this isn't a big deal at this point. My main goal is to get the image displayed in a new window. So after I removed the code above, due to that error I got another one.
Traceback (most recent call last):
File "./widgetarea.py", line 103, in on_open_clicked
self.previewimage.set_from_file(ref_image_path)
AttributeError: 'WidgetArea' object has no attribute 'previewimage'
All I'm having problems with is when you browse to select an image I want the chosen image, when pressed OK to launch as a new window displaying the chosen image in that window, as stated above.
To correct the first error, use gtk.FILE_CHOOSER_ACTION_OPEN instead of gtk.FileChooserAction.OPEN.
The second problem is because there is no variable named image at that point in your code (line 116). Perhaps you are coming from a C++ or Java background, where a name like image can be resolved by looking at the attributes of the enclosing class, i.e. this.image?
In Python you can't do that. You have to assign explicitly to self.image in your addwidget() method. Otherwise the name image remains local to the addwidget() method and is not available outside of it.
This raises a different problem, what happens every time the button gets clicked and addwidget() is called? self.win and self.image are overwritten. That may be what you want, but I'm just calling it to your attention --- it seems a little odd to me.
I have used something like this in one of my projects. And it's working well for me in Linux.
def __init__(self):
# Define all the widgets
image_filter = gtk.FileFilter()
image_filter.set_name("Images")
image_filter.add_mime_type("image/png")
image_filter.add_mime_type("image/jpeg")
image_filter.add_mime_type("image/gif")
image_filter.add_mime_type("image/tiff")
image_filter.add_mime_type("image/svg+xml")
image_filter.add_pattern("*.jpg")
self.ref_file_button = gtk.FileChooserButton('Select Image')
self.ref_file_button.set_size_request(100,30)
self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"])) # set directory path
self.ref_file_button.set_filter(image_filter)
self.ref_file_button.set_tooltip_text('Select Image')
self.ref_file_button.connect("file-set", self.ref_image_selected)
def ref_image_selected(self,widget,data=None):
ref_image_path = widget.get_filename()
print ref_image_path
After getting the path of the image, you can load it using gtk.Image
EDIT:
Your code is a bit erroneous. You are never calling the function addwidget(), and hence self.previewimage is not defined. and so it gives AttributeError.
def __init__(self):
# your code
self.add(vbox)
self.addwidget(200) # I don't know what 'w' is. so I took a random number.
self.show_all()
def on_open_clicked(self, widget, data=None):
ref_image_path = widget.get_filename()
self.previewimage.set_from_file(ref_image_path)
self.addwidg.connect("clicked", self.addwidget)
self.addwidg.connect("clicked", self.change_size)
ref_image_path.destroy()
What is self.addwidg ?
And I am able to view the image now.