Skip to content
Gleb Golovin edited this page Jun 24, 2015 · 4 revisions

This article is a stub. Please help us improve it.

  • Run Winium.Desktop.Driver.exe --verbose

Python

  • Write your calculator.py

    # coding: utf-8
    from selenium import webdriver
    
    driver = webdriver.Remote(
        command_executor='http://localhost:9999',
        desired_capabilities={
            "debugConnectToRunningApp": 'false',
            "app": r"C:/windows/system32/calc.exe"
        })
    
    window = driver.find_element_by_class_name('CalcFrame')
    view_menu_item = window.find_element_by_id('MenuBar').find_element_by_name('View')
    
    view_menu_item.click()
    view_menu_item.find_element_by_name('Scientific').click()
    
    view_menu_item.click()
    view_menu_item.find_element_by_name('History').click()
    
    window.find_element_by_id('132').click()
    window.find_element_by_id('93').click()
    window.find_element_by_id('134').click()
    window.find_element_by_id('97').click()
    window.find_element_by_id('138').click()
    window.find_element_by_id('121').click()
    
    driver.close()
  • Run python calculator.py

C#

namespace ConsoleApplication
{
    using System;

    using OpenQA.Selenium;
    using OpenQA.Selenium.Remote;

    public class Program
    {
        private static void Main(string[] args)
        {
            var dc = new DesiredCapabilities();
            dc.SetCapability("app", @"C:/windows/system32/calc.exe");
            var driver = new RemoteWebDriver(new Uri("http://localhost:9999"), dc);

            var window = driver.FindElementByClassName("CalcFrame");
            var viewMenuItem = window.FindElement(By.Id("MenuBar")).FindElement(By.Name("View"));

            viewMenuItem.Click();
            viewMenuItem.FindElement(By.Name("Scientific")).Click();

            viewMenuItem.Click();
            viewMenuItem.FindElement(By.Name("History")).Click();

            window.FindElement(By.Id("132")).Click(); // 2
            window.FindElement(By.Id("93")).Click(); // +
            window.FindElement(By.Id("134")).Click(); // 4
            window.FindElement(By.Id("97")).Click(); // ^
            window.FindElement(By.Id("138")).Click(); // 8
            window.FindElement(By.Id("121")).Click(); // =

            driver.Close();
        }
    }
}

Python. Код, который пишет код

from selenium import webdriver
from selenium.webdriver import ActionChains
import time

driver = webdriver.Remote(
    command_executor='http://localhost:9999',
    desired_capabilities={
        'app': r'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe'
    })

window = driver.find_element_by_id('VisualStudioMainWindow')
menu_bar = window.find_element_by_id('MenuBar')

menu_bar.click()
menu_bar.find_element_by_name('File').click()
menu_bar.find_element_by_name('New').click()
menu_bar.find_element_by_name('Project...').click()

project_name = 'SpecialForHabrahabr-' + str(time.time())
new_project_win = window.find_element_by_name('New Project')
new_project_win.find_element_by_id('Windows Desktop').click()
new_project_win.find_element_by_name('Console Application').click()
new_project_win.find_element_by_id('txt_Name').send_keys(project_name)
new_project_win.find_element_by_id('btn_OK').click()

text_view = window.find_element_by_id('WpfTextView')
text_view.send_keys('using System;{ENTER}{ENTER}')

actions = ActionChains(driver)
actions.send_keys('namespace Habrahabr{ENTER}')
actions.send_keys('{{}{ENTER}')
actions.send_keys('class Program{ENTER}')
actions.send_keys('{{}{ENTER}')
actions.send_keys('static void Main{(}string{[}{]} args{)}{ENTER}')
actions.send_keys('{{}{ENTER}')
actions.send_keys('Console.WriteLine{(}\"Hello Habrahabr\"{)};')

actions.send_keys('^{F5}')
actions.perform()

package testcases; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.By; import org.openqa.selenium.winium.DesktopOptions; import org.openqa.selenium.winium.WiniumDriver public class calculator {

public static void main(String[] args) throws MalformedURLException, InterruptedException {
    DesktopOptions option = new DesktopOptions();
    option.setApplicationPath("C:\\Windows\\System32\\calc.exe");
    WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999"), option);
    Thread.sleep(5);
    driver.findElement(By.name("Five")).click();
    driver.findElement(By.id("multiplyButton")).click();
    driver.findElement(By.name("Six")).click();
    driver.findElement(By.id("equalButton")).click();

} }

Clone this wiki locally