Ana içeriğe atla

Selenium - Java2

Inheritance:
In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories:
  • subclass (child) - the class that inherits from another class
  • superclass (parent) - the class being inherited from
To inherit from a class, use the extends keyword.
In the example below, the Car class (subclass) inherits the attributes and methods from the Vehicle class (superclass):

Example

class Vehicle {
  protected String brand = "Ford";         // Vehicle attribute  public void honk() {                     // Vehicle method    System.out.println("Tuut, tuut!");
  }
}

class Car extends Vehicle {
  private String modelName = "Mustang";    // Car attribute  public static void main(String[] args) {

    // Create a myCar object    Car myCar = new Car();

    // Call the honk() method (from the Vehicle class) on the myCar object    myCar.honk();

    // Display the value of the brand attribute (from the Vehicle class) and the value of the modelName from the Car class    System.out.println(myCar.brand + " " + myCar.modelName); 
  }
}
Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance.
Like we specified in the previous chapter; Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways.
For example, think of a superclass called Animal that has a method called animalSound(). Subclasses of Animals could be Pigs, Cats, Dogs, Birds - And they also have their own implementation of an animal sound (the pig oinks, and the cat meows, etc.):

 It is useful for code reusability: reuse attributes and methods of an existing class when you create a new class.

class Animal {
  public void animalSound() {
    System.out.println("The animal makes a sound");
  }
}

class Pig extends Animal {
  public void animalSound() {
    System.out.println("The pig says: wee wee");
  }
}

class Dog extends Animal {
  public void animalSound() {
    System.out.println("The dog says: bow wow");
  }
}

class MyMainClass {
  public static void main(String[] args) {
    Animal myAnimal = new Animal();  // Create a Animal object    Animal myPig = new Pig();  // Create a Pig object    Animal myDog = new Dog();  // Create a Dog object
    myAnimal.animalSound();
    myPig.animalSound();
    myDog.animalSound();
  }
}

Yorumlar

Bu blogdaki popüler yayınlar

Selenium WebDriver - Dinamik Web Tablolarla Kod Örnekleri

Verisi sürekli değişen tablolarda XPath kullanılması gerekir. Bunu da tablonun satır ve sütun sayı bilgileriyle yapmak daha doğru olur. Tablo 1: Şirket Grup Kapanış Şimdiki Ücret % Değişim IL&FS Transportation A 337.4 66.5 + 5.4 GRUH Finance Li A 383.8 998.9 + 2.3 IDFC Bank A 351.4 715.9 + 5.1 YES Bank Ltd. A 697.9 669.3 + 3.2 IRB Infrastructure A 271 724.8 + 3.1 Escorts Ltd. A 113.4 890.3 + 5.1 Cox & Kings L A 867 900.8 + 5.5 Bharat Electroni A 176.5 849 + 7.5 Nestle India A 64.8 187.3 + 7.6 Cox & Kings L A 749.4 729.5 + 9.5 JK Tyre & Industries A 687 601.4 + 6 Navin Fluorine Inter A 416.7 865.3 + 8.9 NIIT Technologies A 966.9 117.2 + 9.4 DCB Bank A 853.2 760.2 + 2.4 UCO Bank A 358 719.6 + 9 Coffee Day Enterpris A 53.8 538.6 + 4.1 Kirloskar Oil Engine A 134.1 102.8 + 7.7 Repco Home Finance L A 96.2 449.9 + 8.9 Ajanta Pharma Lt A 161.3 838 + 4.4 CESC Ltd. A 817 490.5 + 4.7 JaiprakashAssociates A 247.3 961.1 + 7.1 Vakrangee A 888.3 652.9 ...

Test Otomasyonu için Intellij IDEA Maven Projesi Oluşturma

Intellij IDEA - File - Project - New tıklayın.  Soldan Maven ı seçin.  İleriye basın.  Group ID, sizin projenizi tanımlayan bir isim olmalı. Bu alanı doldurun. ArtifactId, projenizin adı. Bu alanı doldurun. Project name, artifactID alanına yazdığınız değer gelir. Finish e basın. İlk olarak karşınıza projenizin pom.xml dosyası gelecek. Buraya ilgili bağımlılıkları ekleyin. Selenium için;  https://www.seleniumhq.org/download/maven.jsp  adresindeki güncel bağımlılığı <dependencies> </dependencies> satırlarının arasına ekleyin. Daha sonra sağ altta çıkan uyarıda Import linkine basın. Böylelikle maven belirttiğiniz versiyonun dosyalarını alacaktır. Test framework ü olarak kullandığımız JUnit bağımlılığı için  https://mvnrepository.com/artifact/junit/junit  adresindeki güncel versiyonundan aldığınız satırları yine aynı  <dependencies> </dependencies> satırlarının arasına ekleyin. Daha sonra sağ altta çıkan uya...

TestNG - Notasyonlar (Annotations), Doğrulamalar (Assertions)

TestNG, JUnit ve NUnit kütüphanelerinden etkilenen ve onlara göre daha fazla yetkinlik barındıran bir test kütüphanesidir. TestNG ait özellikler ve kolaylıklar için şunları örnek verebiliriz: Notasyonlar (Annotations) Testlerin kendine has Thread’lerde koşabilmesi testng.xml dosyasıyla testlerin önceliklendirilmesi, gruplandırılması vb. kolaylıklar Kendi içerisinde loglama, raporlama desteği Notasyonlar sayesinde kodun ve oluşturulan raporun kolaylıkla anlaşılması @DataProvider notasyonu sayesinde veriye dayalı test desteği (Data Driven Test) Maven, Jenkins vb. ide ler için eklenti desteği Parametre desteği Notasyonlar: @Test Notasyonu Yazılan otomasyon kodunda test olarak çalışmasını istediğimiz kod parçasının önüne bu notasyonu ekleriz. Bu notasyonu birden fazla kez kullanabiliriz. Eğer herhangi bir parametre tanımlanmadıysa testler alfabetik olarak çalışır.  Aşağıdaki parametreler, hangi testin hangi sırayla çalışacağının, koşturulup koşturulmayacağın...