From 4e8931a864802a8317445197c0d8952f3c242dae Mon Sep 17 00:00:00 2001 From: Pallavi Date: Sat, 22 Jun 2024 21:56:30 +0530 Subject: [PATCH 1/2] add csharpwindowscommands --- .../SeleniumDocs/Interactions/WindowsTest.cs | 42 ++++++++++++- .../webdriver/interactions/windows.en.md | 61 +++++++----------- .../webdriver/interactions/windows.ja.md | 62 +++++++------------ .../webdriver/interactions/windows.pt-br.md | 55 ++++++---------- .../webdriver/interactions/windows.zh-cn.md | 57 ++++++----------- 5 files changed, 122 insertions(+), 155 deletions(-) diff --git a/examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs b/examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs index eadb93b523ac..de7ccf140dbe 100644 --- a/examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs +++ b/examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs @@ -1,9 +1,49 @@ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; namespace SeleniumDocs.Interactions { [TestClass] - public class WindowsTest : BaseTest + public class WindowsTest { + [TestMethod] + public void TestWindowCommands() + { + WebDriver driver = new ChromeDriver(); + driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500); + + // Navigate to Url + driver.Url="https://www.selenium.dev/selenium/web/window_switching_tests/page_with_frame.html"; + //fetch handle of this + String currHandle = driver.CurrentWindowHandle; + Assert.IsNotNull(currHandle); + + //click on link to open a new window + driver.FindElement(By.LinkText("Open new window")).Click(); + //fetch handles of all windows, there will be two, [0]- default, [1] - new window + IList windowHandles = new List(driver.WindowHandles); + driver.SwitchTo().Window(windowHandles[1]); + //assert on title of new window + String title = driver.Title; + Assert.AreEqual("Simple Page", title); + + //closing current window + driver.Close(); + //Switch back to the old tab or window + driver.SwitchTo().Window(windowHandles[0]); + + //Opens a new tab and switches to new tab + driver.SwitchTo().NewWindow(WindowType.Tab); + Assert.AreEqual("", driver.Title); + + //Opens a new window and switches to new window + driver.SwitchTo().NewWindow(WindowType.Window); + Assert.AreEqual("", driver.Title); + + //quitting driver + driver.Quit(); //close all windows + } } } \ No newline at end of file diff --git a/website_and_docs/content/documentation/webdriver/interactions/windows.en.md b/website_and_docs/content/documentation/webdriver/interactions/windows.en.md index dcca990958f5..ac4e29e87fa7 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/windows.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/windows.en.md @@ -23,9 +23,9 @@ current window by using: {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L16-L20" >}} {{< /tab >}} {{< tab header="Python" >}}driver.current_window_handle{{< /tab >}} - {{< tab header="CSharp" >}} - {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L14-L18" >}} - {{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L17-L21" >}} + {{< /tab >}} {{< tab header="Ruby" >}}driver.window_handle{{< /tab >}} {{< tab header="JavaScript" >}}await driver.getWindowHandle();{{< /tab >}} {{< tab header="Kotlin" >}}driver.windowHandle{{< /tab >}} @@ -79,31 +79,11 @@ with webdriver.Firefox() as driver: # Wait for the new tab to finish loading content wait.until(EC.title_is("SeleniumHQ Browser Automation")) {{< /tab >}} - {{< tab header="CSharp" >}} -//Store the ID of the original window -string originalWindow = driver.CurrentWindowHandle; - -//Check we don't have other windows open already -Assert.AreEqual(driver.WindowHandles.Count, 1); - -//Click the link which opens in a new window -driver.FindElement(By.LinkText("new window")).Click(); - -//Wait for the new window or tab -wait.Until(wd => wd.WindowHandles.Count == 2); - -//Loop through until we find a new window handle -foreach(string window in driver.WindowHandles) -{ - if(originalWindow != window) - { - driver.SwitchTo().Window(window); - break; - } -} -//Wait for the new tab to finish loading content -wait.Until(wd => wd.Title == "Selenium documentation"); + + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L23-L30" >}} {{< /tab >}} + {{< tab header="Ruby" >}} # Store the ID of the original window @@ -203,13 +183,11 @@ driver.close() #Switch back to the old tab or window driver.switch_to.window(original_window) {{< /tab >}} - {{< tab header="CSharp" >}} -//Close the tab or window -driver.Close(); - -//Switch back to the old tab or window -driver.SwitchTo().Window(originalWindow); + + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L32-L35" >}} {{< /tab >}} + {{< tab header="Ruby" >}} #Close the tab or window driver.close @@ -259,13 +237,12 @@ driver.switch_to.new_window('tab') # Opens a new window and switches to new window driver.switch_to.new_window('window') {{< /tab >}} - {{< tab header="CSharp" >}} -// Opens a new tab and switches to new tab -driver.SwitchTo().NewWindow(WindowType.Tab) - -// Opens a new window and switches to new window -driver.SwitchTo().NewWindow(WindowType.Window) + + + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L37-L43" >}} {{< /tab >}} + {{% tab header="Ruby" text=true %}} Opens a new tab and switches to new tab: {{< gh-codeblock path="/examples/ruby/spec/interactions/windows_spec.rb#L9" >}} @@ -302,7 +279,11 @@ instead of close: {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L44-L45" >}} {{< /tab >}} {{< tab header="Python" >}}driver.quit(){{< /tab >}} - {{< tab header="CSharp" >}}driver.Quit();{{< /tab >}} + + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L45-L46" >}} + {{< /tab >}} + {{< tab header="Ruby" >}}driver.quit{{< /tab >}} {{< tab header="JavaScript" >}}await driver.quit();{{< /tab >}} {{< tab header="Kotlin" >}}driver.quit(){{< /tab >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/windows.ja.md b/website_and_docs/content/documentation/webdriver/interactions/windows.ja.md index e742cb03420a..b97d8788f64b 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/windows.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/windows.ja.md @@ -21,9 +21,9 @@ WebDriverは、ウィンドウとタブを区別しません。 {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L16-L20" >}} {{< /tab >}} {{< tab header="Python" >}}driver.current_window_handle{{< /tab >}} - {{< tab header="CSharp" >}} - {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L14-L18" >}} - {{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L17-L21" >}} + {{< /tab >}} {{< tab header="Ruby" >}}driver.window_handle{{< /tab >}} {{< tab header="JavaScript" >}}await driver.getWindowHandle();{{< /tab >}} {{< tab header="Kotlin" >}}driver.windowHandle{{< /tab >}} @@ -75,31 +75,12 @@ with webdriver.Firefox() as driver: # Wait for the new tab to finish loading content wait.until(EC.title_is("SeleniumHQ Browser Automation")) {{< /tab >}} - {{< tab header="CSharp" >}} -//Store the ID of the original window -string originalWindow = driver.CurrentWindowHandle; - -//Check we don't have other windows open already -Assert.AreEqual(driver.WindowHandles.Count, 1); - -//Click the link which opens in a new window -driver.FindElement(By.LinkText("new window")).Click(); - -//Wait for the new window or tab -wait.Until(wd => wd.WindowHandles.Count == 2); - -//Loop through until we find a new window handle -foreach(string window in driver.WindowHandles) -{ - if(originalWindow != window) - { - driver.SwitchTo().Window(window); - break; - } -} -//Wait for the new tab to finish loading content -wait.Until(wd => wd.Title == "Selenium documentation"); + + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L23-L30" >}} {{< /tab >}} + + {{< tab header="Ruby" >}} #Store the ID of the original window original_window = driver.window_handle @@ -195,13 +176,12 @@ driver.close() #Switch back to the old tab or window driver.switch_to.window(original_window) {{< /tab >}} - {{< tab header="CSharp" >}} -//Close the tab or window -driver.Close(); -//Switch back to the old tab or window -driver.SwitchTo().Window(originalWindow); + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L32-L35" >}} {{< /tab >}} + + {{< tab header="Ruby" >}} #Close the tab or window driver.close @@ -247,13 +227,12 @@ driver.switch_to.new_window('tab') # Opens a new window and switches to new window driver.switch_to.new_window('window') {{< /tab >}} - {{< tab header="CSharp" >}} -// Opens a new tab and switches to new tab -driver.SwitchTo().NewWindow(WindowType.Tab) - -// Opens a new window and switches to new window -driver.SwitchTo().NewWindow(WindowType.Window) + + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L37-L43" >}} {{< /tab >}} + + {{% tab header="Ruby" text=true %}} Opens a new tab and switches to new tab {{< gh-codeblock path="/examples/ruby/spec/interactions/windows_spec.rb#L9" >}} @@ -261,6 +240,7 @@ Opens a new tab and switches to new tab Opens a new window and switches to new window {{< gh-codeblock path="/examples/ruby/spec/interactions/windows_spec.rb#L15" >}} {{% /tab %}} + {{< tab header="JavaScript" text=true >}} Opens a new tab and switches to new tab {{< gh-codeblock path="examples/javascript/test/interactions/windows.spec.js#L70" >}} @@ -268,6 +248,7 @@ Opens a new tab and switches to new tab Opens a new window and switches to new window: {{< gh-codeblock path="examples/javascript/test/interactions/windows.spec.js#L75" >}} {{< /tab >}} + {{< tab header="Kotlin" >}} // Opens a new tab and switches to new tab driver.switchTo().newWindow(WindowType.TAB) @@ -275,6 +256,7 @@ driver.switchTo().newWindow(WindowType.TAB) // Opens a new window and switches to new window driver.switchTo().newWindow(WindowType.WINDOW) {{< /tab >}} + {{< /tabpane >}} @@ -287,7 +269,9 @@ driver.switchTo().newWindow(WindowType.WINDOW) {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L44-L45" >}} {{< /tab >}} {{< tab header="Python" >}}driver.quit(){{< /tab >}} - {{< tab header="CSharp" >}}driver.Quit();{{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L45-L46" >}} + {{< /tab >}} {{< tab header="Ruby" >}}driver.quit{{< /tab >}} {{< tab header="JavaScript" >}}await driver.quit();{{< /tab >}} {{< tab header="Kotlin" >}}driver.quit(){{< /tab >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/windows.pt-br.md b/website_and_docs/content/documentation/webdriver/interactions/windows.pt-br.md index 006e78279b35..7b3e82285176 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/windows.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/interactions/windows.pt-br.md @@ -21,9 +21,9 @@ persistente em uma única sessão. Você pode pegar o identificador atual usando {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L16-L20" >}} {{< /tab >}} {{< tab header="Python" >}}driver.current_window_handle{{< /tab >}} - {{< tab header="CSharp" >}} - {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L14-L18" >}} - {{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L17-L21" >}} + {{< /tab >}} {{< tab header="Ruby" >}}driver.window_handle{{< /tab >}} {{< tab header="JavaScript" >}}await driver.getWindowHandle();{{< /tab >}} {{< tab header="Kotlin" >}}driver.windowHandle{{< /tab >}} @@ -81,31 +81,13 @@ with webdriver.Firefox() as driver: # Wait for the new tab to finish loading content wait.until(EC.title_is("SeleniumHQ Browser Automation")) {{< /tab >}} - {{< tab header="CSharp" >}} -//Store the ID of the original window -string originalWindow = driver.CurrentWindowHandle; -//Check we don't have other windows open already -Assert.AreEqual(driver.WindowHandles.Count, 1); - -//Click the link which opens in a new window -driver.FindElement(By.LinkText("new window")).Click(); + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L23-L30" >}} + {{< /tab >}} + -//Wait for the new window or tab -wait.Until(wd => wd.WindowHandles.Count == 2); -//Loop through until we find a new window handle -foreach(string window in driver.WindowHandles) -{ - if(originalWindow != window) - { - driver.SwitchTo().Window(window); - break; - } -} -//Wait for the new tab to finish loading content -wait.Until(wd => wd.Title == "Selenium documentation"); - {{< /tab >}} {{< tab header="Ruby" >}} #Store the ID of the original window original_window = driver.window_handle @@ -203,13 +185,11 @@ driver.close() #Switch back to the old tab or window driver.switch_to.window(original_window) {{< /tab >}} - {{< tab header="CSharp" >}} -//Close the tab or window -driver.Close(); -//Switch back to the old tab or window -driver.SwitchTo().Window(originalWindow); + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L32-L35" >}} {{< /tab >}} + {{< tab header="Ruby" >}} #Close the tab or window driver.close @@ -257,13 +237,12 @@ driver.switch_to.new_window('tab') # Opens a new window and switches to new window driver.switch_to.new_window('window') {{< /tab >}} - {{< tab header="CSharp" >}} -// Opens a new tab and switches to new tab -driver.SwitchTo().NewWindow(WindowType.Tab) - -// Opens a new window and switches to new window -driver.SwitchTo().NewWindow(WindowType.Window) + + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L37-L43" >}} {{< /tab >}} + + {{% tab header="Ruby" text=true %}} Opens a new tab and switches to new tab {{< gh-codeblock path="/examples/ruby/spec/interactions/windows_spec.rb#L9" >}} @@ -301,7 +280,9 @@ em vez de fechar: {{< /tab >}} {{< tab header="Python" >}}driver.quit(){{< /tab >}} - {{< tab header="CSharp" >}}driver.Quit();{{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L45-L46" >}} + {{< /tab >}} {{< tab header="Ruby" >}}driver.quit{{< /tab >}} {{< tab header="JavaScript" >}}await driver.quit();{{< /tab >}} {{< tab header="Kotlin" >}}driver.quit(){{< /tab >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/windows.zh-cn.md b/website_and_docs/content/documentation/webdriver/interactions/windows.zh-cn.md index 6a7a1e5d2a3c..cd5ddd41832e 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/windows.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/interactions/windows.zh-cn.md @@ -17,9 +17,9 @@ WebDriver 没有区分窗口和标签页。如果你的站点打开了一个新 {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L16-L20" >}} {{< /tab >}} {{< tab header="Python" >}}driver.current_window_handle{{< /tab >}} - {{< tab header="CSharp" >}} - {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L14-L18" >}} - {{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L17-L21" >}} + {{< /tab >}} {{< tab header="Ruby" >}}driver.window_handle{{< /tab >}} {{< tab header="JavaScript" >}}await driver.getWindowHandle();{{< /tab >}} {{< tab header="Kotlin" >}}driver.windowHandle{{< /tab >}} @@ -74,29 +74,11 @@ driver.get("https://seleniumhq.github.io") # 等待新标签页完成加载内容 wait.until(EC.title_is("SeleniumHQ Browser Automation")) {{< /tab >}} -{{< tab header="CSharp" >}} -// 存储原始窗口的 ID -string originalWindow = driver.CurrentWindowHandle; -// 检查一下,我们还没有打开其他的窗口 -Assert.AreEqual(driver.WindowHandles.Count, 1); - -// 单击在新窗口中打开的链接 -driver.FindElement(By.LinkText("new window")).Click(); - -// 等待新窗口或标签页 -wait.Until(wd => wd.WindowHandles.Count == 2); + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L23-L30" >}} + {{< /tab >}} -// 循环执行,直到找到一个新的窗口句柄 -foreach(string window in driver.WindowHandles) -{if(originalWindow != window) -{driver.SwitchTo().Window(window); -break; -} -} -// 等待新标签页完成加载内容 -wait.Until(wd => wd.Title == "Selenium documentation"); -{{< /tab >}} {{< tab header="Ruby" >}} # 存储原始窗口的 ID original_window = driver.window_handle @@ -188,13 +170,11 @@ driver.close() #切回到之前的标签页或窗口 driver.switch_to.window(original_window) {{< /tab >}} -{{< tab header="CSharp" >}} -//关闭标签页或窗口 -driver.Close(); -//切回到之前的标签页或窗口 -driver.SwitchTo().Window(originalWindow); -{{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L32-L35" >}} + {{< /tab >}} + {{< tab header="Ruby" >}} #关闭标签页或窗口 driver.close @@ -240,13 +220,12 @@ driver.switch_to.new_window('tab') # 打开一个新窗口并切换到新窗口 driver.switch_to.new_window('window') {{< /tab >}} -{{< tab header="CSharp" >}} -// 打开新标签页并切换到新标签页 -driver.SwitchTo().NewWindow(WindowType.Tab) - -// 打开一个新窗口并切换到新窗口 -driver.SwitchTo().NewWindow(WindowType.Window) -{{< /tab >}} + + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L37-L43" >}} + {{< /tab >}} + + {{% tab header="Ruby" text=true %}} 打开新标签页并切换到新标签页 {{< gh-codeblock path="/examples/ruby/spec/interactions/windows_spec.rb#L9" >}} @@ -283,7 +262,9 @@ driver.switchTo().newWindow(WindowType.WINDOW) {{< /tab >}} {{< tab header="Python" >}}driver.quit(){{< /tab >}} -{{< tab header="CSharp" >}}driver.Quit();{{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L45-L46" >}} + {{< /tab >}} {{< tab header="Ruby" >}}driver.quit{{< /tab >}} {{< tab header="JavaScript" >}}await driver.quit();{{< /tab >}} {{< tab header="Kotlin" >}}driver.quit(){{< /tab >}} From e6dda929e93c09d618af0f5beaa581e8ab37afc2 Mon Sep 17 00:00:00 2001 From: Pallavi Date: Fri, 5 Jul 2024 15:04:27 +0530 Subject: [PATCH 2/2] Update WindowsTest.cs --- examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs b/examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs index de7ccf140dbe..f362ad3ba154 100644 --- a/examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs +++ b/examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs @@ -2,7 +2,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; - +using System.Collections.Generic; namespace SeleniumDocs.Interactions { [TestClass] @@ -46,4 +46,4 @@ public void TestWindowCommands() driver.Quit(); //close all windows } } -} \ No newline at end of file +}