Mouse up of a WebElement (Selenium and Java)

Move the mouse up of a controller/WebElement is simple, is just put this line of code:

WebElement valoratual = driver.findElement(By.className(“product-description-catalog-item”));

Robot robot = new Robot();
robot.mouseMove(valoratual.getLocation().getX(), valoratual.getLocation().getY());

 

Yes, you have to catch the X and Y in the page and the robot will put the mouse over thispoint.

 

Bye bye 🙂

Do you need scroll the page ? (Selenium and javascript)

If you need scroll the page for example take a screenshot in a browser different of Firefox (Yes, the selenium have a problem to take a screenshot of the entire page when you are in a different browser like, IE)

So we have to create a function that take a screenshot of parts of the page, and this function helps you to scroll the page.

First you have to import the libraries:

import org.openqa.selenium.JavascriptExecutor;

 

After the code:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“window.scrollTo(0,Math.max(document.documentElement.scrollHeight,”
+ “document.body.scrollHeight,document.documentElement.clientHeight));”);

 

After this, the driver will scroll until the end of the current page.

I hope that I help you 🙂

Mark element in the page with red border (Javascript with Selenium)

Hello again, now I will give a tip of Selenium, for mark the element that you want and before this, you can take a screenshot for evidence.

First you have to import this libraries:

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;

 

After this, you have to call the javascript executor and give the id or other thing for find the element:

JavascriptExecutor js = (JavascriptExecutor) driver; // change the name of your WebDriver
WebElement element = driver.findElement(By.id(“element“)); // change the localizator 

js.executeScript(“arguments[0].style.border=’3px solid red'”, element); // change the name of your variable

 

This is very usefull for mark the element in the page.

So, just this ! Bye bye 🙂

What a constructor do ?

Hum.. I always forget the function of a constructor because I don’t have the custom to use.

For this reason, I will put here some tips:

A constructor  is a method with instructions that will execute ALWAYS  when will instantiated a object of this class.

Like this:

  • Class MyClass.java
 public class MyClass {

public MyClass() { //this is the constructor method
System.out.println(“Hello World !”);
}  }

In the constructor method will be wrrte “Hello World !”

So… when you call this class, the constructor will be execute.

 

  • Class Test.java
 public class Test {

public static void main(String args[]) {
MyClass Obj1 = new MyClass();
}
}

It’s simple no ? It is just a method that will be execute before others methods when you call this class.
Bye bye !

The best small caps in March

Sao Paulo – With changes in index of small caps of Bovespa, the compiled of stocks more recommended made by InfoMoney shows a different result  of last month. In the third month of 2013, the America Latina Logistica (ALLL3), wich not was in the february index, is in the first position with six votes between 25 of analysed portfolio.

The second place was with Anhanguera (AEDU3), wich was recommended in five of 25 analysed portfolio. The third place was divided between the companies Even (EVEN3) and PDG Realty (PDGR3), wich were cited three times each.

 

Others recommendations:

Alpargatas (ALPA4), Eztec (EZTC3), Grendene (GRND3), Iguatemi (IGTA3), Kroton (KROT3), Marfrig (MRFG3), Iochp-Maxion (MYPK3), Marcopolo (POMO4), Randon (RAPT4), SĂŁo Martinho (SMTO3), V-Agro (VAGR3) e Valid (VLID3).

 

With one vote each, close the list of recommendations the papers of  Aliansce (ALSC3), Lojas Marisa (AMAR3), Banrisul (BRSR6), Equatorial (EQTL3), Fleury (FLRY3), Gafisa (GFSA3), Helbor (HBOR3), Metal Leve (LEVE3), Le Lis Blanc (LLIS3), Magnesita (MAGG3), Mils (MILS3), MRV (MRVE3), Odontoprev (ODPV3), Paranapanema (PMAM3), Qualicorp (QUAL3), Rossi Residencial (RSID3), SierraBrasil (SSBR3) e Santos BRP (STBP11).

 

Font: http://www.infomoney.com.br/onde-investir/acoes/noticia/2697172/small-caps-mais-recomendadas-para-marco-por-corretoras

How can I call the drivers(browsers) in Selenium with java ?

It’s simple !

you have to call the import > import org.openqa.selenium.WebDriver; and others about the browsers, like: import org.openqa.selenium.firefox.FirefoxDriver; (calls Firefox)

After this, in the class Main, declare driver:

WebDriver driver;

and Quit:

Quit quit = new Quit();

So… you have now choose what is the browser and calls the profile and set the configs, like proxy (for this reason you have to create a profile)

public class Main {

public static void main(String[] args) throws Exception {

FirefoxProfile profile = new FirefoxProfile();   // create a profile of Firefox
profile.setPreference(“network.proxy.type”, 0);   // Don’t use proxy
driver = new FirefoxDriver(profile);       // calls the browser with the configs of the profile
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);     // config the timeouts for load a page
driver.get(site);     // change site for the url that your driver will open.

quit.tearDown(driver);     // quit the driver.

}

}

You have to create the class that close the driver in class Main.

public class Main {

public static class Quit {

public void tearDown(WebDriver driver) {
driver.close();
driver.quit();
}

}

and finish !

This is the first step for create a automation with selenium. Create a driver and open the browser !

Good studies for all, bye !

Inherit with java

You can do the class inherit other like this: 

class NomeDaClasseASerCriada extends NomeDaClasseASerHerdada

We show an sample:

Class 1: Eletrodomestico

package tiexpert;

public class Eletrodomestico {
private boolean ligado;
private int voltagem;
private int consumo;
public Eletrodomestico(boolean ligado, int voltagem, int consumo) {
  this.ligado = ligado;
  this.voltagem = voltagem;
  this.consumo = consumo;
  }
// (...)
}
Class 2: TV
package tiexpert;

public class TV extends Eletrodomestico {
private int canal;
private int volume;
private int tamanho;
public TV(int voltagem, int consumo, int canal, int volume, int tamanho) {
  super(false, voltagem, consumo);
  this.canal = canal;
  this.volume = volume;
  this.tamanho = tamanho;
 }
 //(...)
}
Instance:
package tiexpert;

public class ExemploHeranca {
  public static void mostrarCaracteristicas(TV obj) {
   System.out.print("Esta TV tem as seguintes características:\n"
   + "Tamanho: " + obj.getTamanho() + "\"\n"
   + "Voltagem Atual: "+ obj.getVoltagem() + "V\n"
   + "Consumo/h: " + obj.getConsumo() + "W\n");
   if (obj.isLigado()) {
    System.out.println("Ligado: Sim\n"
   + "Canal: " + obj.getCanal() + "\n"
   + "Volume: " + obj.getVolume()+"\n");
   } else {
  System.out.println("Ligado: Não\n");
 }
}
public static void main(String args[]) {
  TV tv1 = new TV(110, 95, 0, 0, 21);
  TV tv2 = new TV(220, 127, 0, 0, 29);
  tv2.setLigado(true);
  tv2.setCanal(3);
  tv2.setVolume(25);
  mostrarCaracteristicas(tv1);
  mostrarCaracteristicas(tv2);
 }
}
Let’s trainning !!
Font: http://www.tiexpert.net/programacao/java/heranca.php

How we can find a line in some table with Webdriver (Selenium) ?

Hi guys, I’m very occupied in the last months, but I will post a text about catch the lines and values in some table with Webdriver (selenium) in language java. Yes, I am changing a little the subjects, this time I will help the testers, who do automation of sites.

It’s easy if you use XPath.

This table:

Apples 44%
Bananas 23%
Oranges 13%
Other 10%

/html/body/div[1]/div/div[4]/div[2]/div[2]/table/tbody/tr[1]

You catched the first line.

If you want catch the second line, just change the number:

/html/body/div[1]/div/div[4]/div[2]/div[2]/table/tbody/tr[2]

It’s more easy than you expected, not ?

if you want catch all the text of all lines, just write the code:

WebElement listatable = driver.findElement(By.className(“reference”));

for (int i = 0; i < listatable.getLength(); i++) {

WebElement line = driver.findElement(By.xpath(“/html/body/div[1]/div/div[4]/div[2]/div[2]/table/tbody/tr[” + i + “]”));

line.getText();

}

Fine, now you can catch the text of each line in this table !

I hope has helped the initial testers in something.

Bye bye !

Polymorphism – C#

What is ?

It let invoke methods of the class through of a reference class base during a run-time. This is useful when you have a array and you have to invoke each method of him. they don’t need be the same type of the object.

using System;

public class DrawingObject
{
public virtual void Draw();
{
Console.WriteLine(“I’m just a generic drawing object.”);
}
}

This will be the base for others objects of classes inherit. The method Draw() performs the only action of print the declaration.

using System;

public class Line : DrawingObject
{
public override void Draw();
{
Console.WriteLine(“I’m a Line.”);
}
}

public class Circle : DrawingObject
{
public override void Draw()
{
Console.WriteLine(“I’m a Circle.”);
}
}

public class Square : DrawingObject
{
public override void Draw()
{
Console.WriteLine(“I’m a Square.”);
}

}

Show 3 classes, and this classes are inherited the DrawingObject. Each class have a method Draw() and each Draw() have a modifier override.

using System;

public class DrawDemo
{
public static int Main( )
{
DrawingObject[] dObj = new DrawingObject[4];

dObj[0] = new Line();
dObj[1] = new Circle();
dObj[2] = new Square();
dObj[3] = new DrawingObject();

foreach (DrawingObject drawObj in dObj)
{
drawObj.Draw();
}

return 0;
}

}

This program implements polimorphism. In the method Main() of class DrawDemo, there is a range wich are being created. The type of the object in this matrix is a DrawingObject class. The matrix is called dObj and is being initialized for stop four objects of type DrawingObject.

Output:

I’m a Line.
I’m a Circle.
I’m a Square.

I’m just a generic drawing object.

The override method Draw() of each derived performs how shown on the program DrawDemo. The las line is starting of virtual Draw() DrawingObject method of the class. This, because the real run-time type of fourth element was an array DrawingObject object.

So, this is only a summary about polimorphism in C#. Hope this help every one to start use this resource.

Font: http://www.oficinadanet.com.br/artigo/885/curso_de_c_sharp_licao_9_polimorfismo

I sold my property and I will pay rent

Hello again, I found a news about the last subject. For this reason I translated a little bit of the text…

Change own property by itself to take advantage of high prices is a decision that involves significant changes in personal finances.Reporting by Luciana Seabra, Valor, took up in detail of the subject and told how two couples decided to give up the security of their own home to live paying rent. And how are they doing to manage the anxiety of having to invest large amount of funds received after the sale of the property and simultaneously follow the evolution of the property market.

[…]

Firstly, it is important consider that rents are adjusted annually for inflation and this way should be the concerned with preserving the purchasing power of the value of the application. One problem is that the standard adjustment of rents is the IGP-M, but it is not common find investments corrected by this index.

The best solution, then is invest in securities adjusted by the IPCA, considering that in the long term the trend is that all inflation indices have similar variation.

The second equally important factor is the solidness of the investment, especially considering that the amounts involved are high and the fact that, generally, the property where the couple lives represents a high fraction of the total richness of the family.

Change the security of the own property by income from financial investments, it is necessary that the investment has the least possible chance of suffer some sort of indebtedness. The safest option is government bonds.

The third point for to consider is the need for periodic liquidity for a small part of the total application. That’s because you need to use part incomes for pay the rent and the best alternative to fill this requirement are the roles that pay regular income every six months.

Finally, the ideal is that the application is long-term, to reduce the risk that the premises which were used to support the decision to sell for rent change drastically.

An investment option that combines all the features above is the NTN-B with maturity in 2045 traded at Treasury Direct.

[…]

And I hope this text can helps you, like me. Because I always thought that the NTN-F with maturity in 07.01.17 would the better choice.

Font: http://www.valor.com.br/valor-investe/o-consultor-financeiro/2551514/vendi-meu-imovel-e-vou-pagar-aluguel