top of page

Selenium - Python,Ruby,Java ve CSharp Donusumleri

  • Writer: Sevdanur GENC
    Sevdanur GENC
  • Mar 30, 2013
  • 3 min read

Selenium'un bize HTML formatinda hazirlamis oldugu test case'leri Python, Ruby, Java ve CSharp dillerinde kullanabilecegimiz test case'lere nasil donusturecegimizi inceleyecegiz. En bastan beri kullanmis oldugum ornek uygulama uzerinden gidelim ve donusumleri nasil yaptigimizdan adim adim bahsetmeye baslayalim.

                Selenium'un kullanmis oldugu kodlari istedigimiz bu dort dilden birisine donusturebilmemiz icin File menusunden Export Test Case As... 'i tikliyoruz. Menunun altlarina dogru ikinci kisimda ise olusturmus oldugunuz tum test case'leri birlestirerek kullanmis oldugunuz test suite'ler icin dil donusumleri bulunmaktadir. Export Test Case As... 'den WebDriver ile ilgili unit ifadeleri seciyor olacagiz.

                              Dilerseniz hepsini sirayla olusturalim ve inceleyelim. Bununla birlikte isterseniz Ruby, Python, Java ve CSharp'a ait derleyicilerinizde bu test case'leri calistirabilirsiniz.  

NanonunGunlugu.Ruby Kaynak Kodlari;

require "selenium-webdriver" gem "test-unit" require "test/unit" class NanonunGunlugu < Test::Unit::TestCase def setup @driver = Selenium::WebDriver.for :firefox @base_url = "https://sevdanurgenc.com/" @accept_next_alert = true @driver.manage.timeouts.implicit_wait = 30 @verification_errors = [] end def teardown @driver.quit assert_equal [], @verification_errors end def test_nanonun_gunlugu @driver.get(@base_url + "/") @driver.find_element(:css, "a

").click @driver.find_element(:link, "TDD – Test Driven Development").click @driver.find_element(:css, "a

").click @driver.find_element(:name, "s").clear @driver.find_element(:name, "s").send_keys "Selenium" @driver.find_element(:css, "input.button").click end def element_present?(how, what) @driver.find_element(how, what) true rescue Selenium::WebDriver::Error::NoSuchElementError false end def verify(&blk) yield rescue Test::Unit::AssertionFailedError => ex @verification_errors << ex end def close_alert_and_get_its_text(how, what) alert = @driver.switch_to().alert() if (@accept_next_alert) then alert.accept() else alert.dismiss() end alert.text ensure @accept_next_alert = true end end

NanonunGunlugu.Py Kaynak Kodlari;

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException import unittest, time, re class NanonunGunlugu(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "https://sevdanurgenc.com/" self.verificationErrors = [] self.accept_next_alert = true def test_nanonun_gunlugu(self): driver = self.driver driver.get(self.base_url + "/") driver.find_element_by_css_selector("a

").click() driver.find_element_by_link_text("TDD – Test Driven Development").click() driver.find_element_by_css_selector("a

").click() driver.find_element_by_name("s").clear() driver.find_element_by_name("s").send_keys("Selenium") driver.find_element_by_css_selector("input.button").click() def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException, e: return False return True def close_alert_and_get_its_text(self): try: alert = self.driver.switch_to_alert() if self.accept_next_alert: alert.accept() else: alert.dismiss() return alert.text finally: self.accept_next_alert = True def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors) if __name__ == "__main__": unittest.main()  

NanonunGunlugu.Java Kaynak Kodlari;

package com.example.tests; import java.util.regex.Pattern; import java.util.concurrent.TimeUnit; import org.junit.*; import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.*; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; public class NanonunGunlugu { private WebDriver driver; private String baseUrl; private boolean acceptNextAlert = true; private StringBuffer verificationErrors = new StringBuffer(); @Before public void setUp() throws Exception { driver = new FirefoxDriver(); baseUrl = "https://sevdanurgenc.com/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @Test public void testNanonunGunlugu() throws Exception { driver.get(baseUrl + "/"); driver.findElement(By.cssSelector("a

")).click(); driver.findElement(By.linkText("TDD – Test Driven Development")).click(); driver.findElement(By.cssSelector("a

")).click(); driver.findElement(By.name("s")).clear(); driver.findElement(By.name("s")).sendKeys("Selenium"); driver.findElement(By.cssSelector("input.button")).click(); } @After public void tearDown() throws Exception { driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } } private boolean isElementPresent(By by) { try { driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; } } private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alert.getText(); } finally { acceptNextAlert = true; } } }  

NanonunGunlugu.Cs Kaynak Kodlari;

using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests {

public class NanonunGunlugu { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true;

public void SetupTest() { driver = new FirefoxDriver(); baseURL = "https://sevdanurgenc.com/"; verificationErrors = new StringBuilder(); }

public void TeardownTest() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); }

public void TheNanonunGunluguTest() { driver.Navigate().GoToUrl(baseURL + "/"); driver.FindElement(By.CssSelector("a

")).Click(); driver.FindElement(By.LinkText("TDD – Test Driven Development")).Click(); driver.FindElement(By.CssSelector("a

")).Click(); driver.FindElement(By.Name("s")).Clear(); driver.FindElement(By.Name("s")).SendKeys("Selenium"); driver.FindElement(By.CssSelector("input.button")).Click(); } private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } } private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alert.Text; } finally { acceptNextAlert = true; } } } } Keyifli Calismalar Dilerim..

Recent Posts

See All
Oracle Java Cloud Service Uygulamasi

Bir onceki Oracle Cloud Computing yazisinda bahsettigim gibi JDeveloper Oracle Cloud icin gelistirmis oldugu surumu olan Oracle JDeveloper 11g (11.1.1.6.0) ile kucuk bir uygulama gelistirip bunu oracl

 
 
 
Oracle Cloud Computing Hakkinda

Bulut bilisim konusundaki arastirmalarima devam ederken bu kez solugu Oracle Cloud Computing'de aldim. Bu makalem ve ilerleyen makalelerimde Trial versiyonu ile user tarafini pek yormayan bir yapidan

 
 
 
Nested Parallel Loops

Matrix Multiplication / Matrix Carpma islemlerini OpenMP araciligi ile paralel alanda nasil yapilabilecegini incelerken ayni zamanda for construct'larin nested parallel loops alaninda nasil calistigin

 
 
 

Comments


©2035 by Sevdanur Genc. Powered and secured by Wix

bottom of page