I am a beginner in Selenium.
I have very long scroll-able form which will automation script will fill, is there a way where I can take screenshot when the page is scrolled down every time (web-driver scrolls to fill the form, I haven't scripted to scroll down as web-driver takes care of it), so that the entire form can be captured in multiple screenshots.
Here is how I would do it. On every swipe You can take screenshot, like as step screenshot.
Here is part of code for screenshot take:
public static String takeScreenshot(WebDriver driver) {
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
File dest = new File("c:\\tmp\\screenshot.png");
FileUtils.copyFile(scrFile, dest);
return dest.getAbsolutePath();
}
And here is the code for vertical swipe:
public static void swipeVertical(WebDriver driver) {
Dimension size = driver.manage().window().getSize();
System.out.println(size);
int starty = (int) (size.height * 0.70);
int endy = (int) (size.height * 0.30);
int startx = size.width / 2;
new TouchAction(driver)
.press(startx, starty)
.waitAction(Duration.ofMillis(1000))
.moveTo(startx, endy)
.release()
.perform();
}
so my pseudo code would look like this:
WebDriver driver = initDriver();
load page and elements
inputText(text);
takScreenShot(driver);
swipe(driver);
...
repeat until end...
You can capture as many screenshots as you want. After fill in each column, after fill in each third column, whatever.
Or you can let the webdriver fill in the whole form and scroll up/down using press pgup/pgdn simulation:
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Robot rob = new Robot();
rob.keyPress(KeyEvent.VK_PAGE_DOWN);
rob.keyRelease(KeyEvent.VK_PAGE_DOWN);
Related
I have a simple GTK3 grid layout using images as buttons and I want to replace the images when various things happen.
What's weird is that this works fine if I replace/remove the image from the same piece of code each time but not when I alternate between the two different sources despite (as far as I can see) everything being almost identical.
Anyway, here's my code...
Initial setup - create pixbuf, make it an image, attach it to the button - this works fine:
/*
* Initial setup
*
* dbp is a pointer to a struct that contains the button, the pixbuf, etc.
*/
// Create new blank (&transprent) image
dbp->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, innerButton.width, innerButton.height);
gdk_pixbuf_fill(dbp->pixbuf, 0x00000000);
// Image holds pixbuf
dbp->image = (GtkImage*)gtk_image_new_from_pixbuf(dbp->pixbuf);
// Attach image to button
gtk_button_set_image(GTK_BUTTON(dbp->btn), GTK_WIDGET(dbp->image));
// Attach button to grid
gtk_grid_attach(GTK_GRID(_grid), dbp->btn, c, r, 1, 1);
Clear image code - blanks the image (transparent):
gdk_pixbuf_fill(dbp->pixbuf, 0x00000000);
Button refresh callback (updates image from pixbuf):
if(dbp->image_modified != 0)
{
gtk_image_set_from_pixbuf(GTK_IMAGE(dbp->image), dbp->pixbuf);
dbp->image_modified = 0;
}
1st image replacement code - takes data input in our own format & creates new pixbuf:
GdkPixbuf *newpixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, BITMAP_WIDTH, BITMAP_HEIGHT);
g_object_unref(dbp->pixbuf);
// <Data unpacked to pixels here, code removed for clarity>
dbp->pixbuf = gdk_pixbuf_copy(newpixbuf);
gdk_pixbuf_copy_options(newpixbuf , dbp->pixbuf);
dbp->image_modified = 1; // Trigger refresh
2nd image replacement - loads image from file and creates new pixbuf:
GdkPixbuf *newpixbuf = gdk_pixbuf_new_from_file_at_scale (file_path, BITMAP_WIDTH, BITMAP_HEIGHT, FALSE, &err);
// [Error check code removed for clarity]
g_object_unref(dbp->pixbuf);
dbp->pixbuf = gdk_pixbuf_copy(newpixbuf );
gdk_pixbuf_copy_options(newpixbuf , dbp->pixbuf);
dbp->image_modified = 1; // Trigger refresh
Now, if I do repeated calls to these routines I get odd interactions;
If I do clear, image_replace_1, clear, image_replace_1, clear, image_replace_1 etc... it works absolutely perfectly.
If I do clear, image_replace_2, clear, image_replace_2, clear, image_replace_2 etc... it works absolutely perfectly.
However, when I do:
If I do clear, image_replace_1, clear, image_replace_2, clear, image_replace_1... it falls over with complaints that GDK_IS_PIXBUF(pixbuf) failed and I can't for the life of me work out how that happens?
I have also tried this alternative code for the button refresh callback;
dbp->image = (GtkImage*)gtk_image_new_from_pixbuf(dbp->pixbuf);
gtk_button_set_image(GTK_BUTTON(dbp->btn), GTK_WIDGET(dbp->image));
But the result is the same.
I created a code that works, but I'm not sure that it's the best way to place an Image scaled automatically to the available width space. I need to put some content over that image, so I have a LayeredLayout: in the first layer there is the Label created with the following code, on the second layer there is a BorderLayout that has the same size of the Image.
Is the following code fine or is it possible to do better?
Label background = new Label(" ", "NoMarginNoPadding") {
boolean onlyOneTime = false;
#Override
public void paint(Graphics g) {
int labelWidth = this.getWidth();
int labelHeight = labelWidth * bgImage.getHeight() / bgImage.getWidth();
this.setPreferredH(labelHeight);
if (!onlyOneTime) {
onlyOneTime = true;
this.getParent().revalidate();
}
super.paint(g);
}
};
background.getAllStyles().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
background.getAllStyles().setBgImage(bgImage);
Shorter code:
ScaleImageLabel sl = new ScaleImageLabel(bgImage);
sl.setUIID("Container");
You shouldn't override paint to set the preferred size. You should have overriden calcPreferredSize(). For ScaleImageLabel it's already set to the natural size of the image which should be pretty big.
i have a scene in which after a particular time the slide show of
images should start.
i have created the texture array and loaded the images to array in
inspector.
now i need to slide each image after every two seconds.
this is the code i have done but it is error
public Texture[] Images;
void ChangeImage()
{
for(int i=1;i<Imagez.Length;i++)
{
print (Imagez [i].ToString());
Imag =Imagez [i];
}
}
i try to load each image from the array, but i know that its not the proper way..can any one please help
Add a scroll rect then add a panel for container and make that panel the scroll rect to control.
Then the container gets a Horizontal/VerticalLayoutGroup. Add all of your images and set the container size so they show properly.
Run the game, you should be able to scroll them appropriately (make sure you constrain the movement hor/vert so it moves correctly).
private int currentIndex = 0;
[SerializeField] private float imageSize;
[SerializeField] private RectTransform panel;
[SerializeField] private float frequency;
void Start()
{
InvokeRepeating("IncreaseCurrentIndex", frequency,frequency);
}
private void IncreaseCurrentIndex()
{
if(++this.currentIndex >= this.imageCount){ this.currentIndex = 0; }
}
void MoveToNextItem()
{
float targetX = (float)this.currentIndex * this.imageSize;
Vector2 delta = this.panel.anchoredPosition;
delta.x = Mathf.MoveTowards(delta.x, targetX, Time.deltaTime * speed);
this.panel.anchoredPosition = delta;
}
First you give the size of the image in the inspector. The panel is the container for all the images. I guess the rest is self explanatory.
The code is as simple as possible, it could benefit more flexibility but at least it should go as is.
NOTE: This is meant to be for horizontal scrolling. You would change the x for y in the update for vertical scrolling. Also, it uses Mathf.MoveTowards, you could use lerp instead of the velocity of scroll rect.
I have a gif file added in cn1 through add animation. But what I need is for it to run only once, then stick in the bottom of the screen. Now it is looping continuously all the time.
code:
#Override
protected void beforeAnimation(Form f) {
leaf = (Image) r.getImage("leafFinal.gif");
leafLabel = new Label(leaf);
f.add(FlowLayout.encloseIn(leafLabel));
leafLabel.setVisible(false);
}
#Override
protected void postAnimation(Form f) {
leafLabel.setVisible(true);
leafLabel.getParent().animateLayoutAndWait(2500);
}
How can I get the gif to not run continuosly?
Update: Using scaleImageLabel instead of Label
ScaleImageLabel leafGifImageLabel = new ScaleImageLabel();
f.add(FlowLayout.encloseIn(leafGifImageLabel));
leafGifImageLabel.setVisible(true);
Image leafGif = (Image) r.getImage("800_ng.gif");
Timeline tLeaf = (Timeline) leafGif;
tLeaf.setLoop(false);
leafGifImageLabel.setIcon(tLeaf);
leafGifImageLabel.getParent().revalidate();
It works if i use scaledImageLabel instead of Label but it cancels out transition of other components. And the gif runs very very very slow in devices.
Downcast the image to timeline and use setLoop(false) as such:
Timeline tLeaf = (Timeline) r.getImage("leafFinal.gif");
tLeaf.setLoop(false);
leaf = tLeaf;
Notice that this might start before the transition completed so write this code as:
f.addShowListener(e -> {
Timeline tLeaf = (Timeline) r.getImage("leafFinal.gif");
tLeaf.setLoop(false);
myLabel.setIcon(tLeaf);
myLabel.getParent().revalidate();
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm new to Flash and intermediate in HTML/CSS. I would like to create a grid of buttons that when you hover over them, they change color and show a linkable caption/tooltip on hover. I would also like this to be dynamic as possible as I will need a grid of 2000+ buttons/squares that may have to be updated from time to time.
Here is an example created with HTML/CSS and some JS
//<![CDATA[
$(window).load(function(){
// Create the tooltips only when document ready
$(document).ready(function () {
// This will automatically grab the 'title' attribute and replace
// the regular browser tooltips for all <a> elements with a title attribute!
$('a[title]').qtip();
});
});//]]>
I need to know the best way to build this in flash, and would really appreciate a barebones breakdown of the code/AS. I am somewhat new to flash and this is just way above my head.
Thanks in advance.
Ok, so you want grid of small bitmaps/shapes on stage. I would recommend bitmaps since they work better when you want to transform something - but if the grid will be standing still, then you can use Sprite filled with color. Below you can find a snippet complete example. You can compile it using mxmlc compiler or using Flash Develop||FDT, or connecting this file as a document class in Flash IDE.
It's the most efficient way I can imagine. We have only one Sprite and we color some parts of it depending on where our mouse is. Hope this helps.
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
/**
* ...
* #author
*/
public class Main extends Sprite
{
private var color:int = 0xf2f2f2;
private var color1:int = 0xff000;//colors definition
private var size:int = 12;//size of our square
private var container:Sprite;//container definition
private var rows:int = 48;//number of rows
private var margin:int = 2;//margin on each side
private var count:int = 2000;//number of elements
private var totalspace:int = size + margin;
private var currentPoint:Point = new Point();
private var lastPoint:Point = null;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
container = new Sprite();//define squares container;
container.graphics.beginFill(color);//define fill color;
var posX:int;
var posY:int;
for ( var i:int = 0; i < count; i++) {
posX = int(i % rows) * totalspace;//calculate x axis position based on modulo
posY = int(i / rows) * totalspace;//calculate y axis position
container.graphics.drawRect( posX, posY, size, size );//call drawRect method on graphics object.
}
addChild(container);//add container to stage - meaning it will be visible, because flash is rendering it.
container.buttonMode = true;//set mouse to button mode
container.addEventListener( MouseEvent.MOUSE_MOVE, onMM );
container.addEventListener( MouseEvent.ROLL_OUT, onMO );
//add eventListener for mouse move - so each time you move a mouse over container object it will trigger an event.
}
private function onMO(e:MouseEvent):void
{
currentPoint = null;
}
private function onMM(e:MouseEvent):void
{
if ( lastPoint == currentPoint ) {
//if moouse is on the same square exit this function
return;
}
//calculate x and y position of square we need to color
currentPoint = new Point( int( container.mouseX/totalspace ) * totalspace, int(container.mouseY/totalspace) * totalspace );
container.graphics.beginFill( color1 );
container.graphics.drawRect( currentPoint.x, currentPoint.y, size, size );
if ( lastPoint ) {
//if last point is present, make it grey, as for roll out
container.graphics.beginFill( color );
container.graphics.drawRect( lastPoint.x, lastPoint.y, size, size );
}
lastPoint = currentPoint;
}
}
}