<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Hani</title>
    <description>The latest articles on Forem by Hani (@sebhani).</description>
    <link>https://forem.com/sebhani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F171255%2F119ea13a-d9d2-4f65-b233-e20500c02762.jpg</url>
      <title>Forem: Hani</title>
      <link>https://forem.com/sebhani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sebhani"/>
    <language>en</language>
    <item>
      <title>An Overview of Turing Machines</title>
      <dc:creator>Hani</dc:creator>
      <pubDate>Fri, 10 Jan 2020 19:25:06 +0000</pubDate>
      <link>https://forem.com/sebhani/an-overview-of-turing-machines-31b8</link>
      <guid>https://forem.com/sebhani/an-overview-of-turing-machines-31b8</guid>
      <description>&lt;p&gt;The famous mathematician Alan Turing introduced the &lt;strong&gt;abstract concept&lt;/strong&gt; of a Turing machine as a part of his research on a problem that was introduced in 1928 by David Hilbert called Entscheidungsproblem. The importance of Turing machines arises because they're one of the first theoretical models for computers and, consequently, a number of theories and ideas in the computer science field were based on this concept. In this post, I'm going to walk you through Turing Machines' concept.&lt;/p&gt;

&lt;p&gt;There are multiple versions of Turing machines, but the most popular and intuitive one is the standard Turing machine (STM). Throughout this post, the STM will be used.&lt;/p&gt;

&lt;h2&gt;Table of Contents&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Informal Definition&lt;/li&gt;
&lt;li&gt;Formal Definition&lt;/li&gt;
&lt;li&gt;Transitions&lt;/li&gt;
&lt;li&gt;Language acceptors VS. transducers&lt;/li&gt;
&lt;li&gt;Example&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id="title1"&gt;Informal Definition&lt;/h2&gt;

&lt;p&gt;Turing machine has a tape which is infinite from both sides of the input. The following picture visualizes the tape of the input aabbcc:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcqebfpc2atg27rzxirw4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcqebfpc2atg27rzxirw4.png" alt="Turing machine tape of input string aabbcc"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cells on each side of the input are empty (i.e. blanks) and denoted by the symbol □.&lt;/p&gt;

&lt;p&gt;There's a scanner that scans the cell content and performs the next action based on the scanned input. The next action can be writing in the current cell and then moving left/right. In the initial configuration of the Turing machine, the scanner is set to the leftmost character of the input as the following picture shows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwf2vxa01v6u8225oyyr0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwf2vxa01v6u8225oyyr0.png" alt="Initial configuration of TM with input string aabbcc"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Turing machine accepts strings that halt in a final state which merely depends on the scanner (which has a kind of a Finite automaton). &lt;strong&gt;Therefore, we can conclude that the tape contents are irrelevant to the acceptance of strings.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Turing machine rejects strings that halt in a non-final states or don't halt at all. In the latter case, the Turing machine runs into an infinite loop because of the input string.&lt;/p&gt;

&lt;h2 id="title2"&gt;Formal Definition&lt;/h2&gt;

&lt;p&gt;The formal definition is easier to understand when it's read simultaneously with a real example. If you feel that you are unable to digest the definition, take a look at the example provided in Example section.&lt;/p&gt;

&lt;p&gt;A Turing machine M is defined by&lt;br&gt;
M = (Q,Σ,Γ,δ,q0, ,F) where&lt;br&gt;
Q is the set of internal states,&lt;br&gt;
Σ is the input alphabet&lt;br&gt;
Γ is the finite set of symbols called the tape alphabet,&lt;br&gt;
δ is the transition function,&lt;br&gt;
□ ∈ Γ is a special symbol called the blank,&lt;br&gt;
q0 ∈ Q is the initial state,&lt;br&gt;
F ⊆ Q is the set of final states.&lt;/p&gt;

&lt;p&gt;In the definition of a Turing machine, we assume that Σ ⊆ Γ – {□}, that is, that the input alphabet is a subset of the tape alphabet, not including the blank. Blanks are ruled out as input for reasons that will become apparent shortly. The transition function δ is defined as δ : Q × Γ → Q × Γ × {L,R}.&lt;/p&gt;

&lt;h2 id="title3"&gt;Transitions&lt;/h2&gt;

&lt;p&gt;δ(q, a) = (q0, b,R) means that from state q, if you see a on tape, go to state q0, write b on tape, and move one square to the right on the tape.&lt;/p&gt;

&lt;p&gt;δ(q, a) = (q0, b, L) means same as above, except move left on the tape.&lt;/p&gt;

&lt;p&gt;What if δ(q, a) is undefined ? (i.e. δ(q, a) = Φ, there is no move corresponds to the pair of (q,a)). Simply, we say that the Turing machine halts. As discussed earlier, if the machine halts in a final state, it accepts the input string. Otherwise, it rejects the input string.&lt;/p&gt;

&lt;h2 id="title4"&gt;Language acceptors VS. transducers&lt;/h2&gt;

&lt;p&gt;A Turing machine that accepts a specific language, similar to finite automata and PDAs, is called language acceptor.&lt;/p&gt;

&lt;p&gt;A Turing machine that take an input string and transforms it to an output is called transducers.&lt;/p&gt;

&lt;h2 id="title5"&gt;Example&lt;/h2&gt;

&lt;p&gt;Let's take the language L={a&lt;sup&gt;n&lt;/sup&gt;b&lt;sup&gt;n&lt;/sup&gt;c&lt;sup&gt;n&lt;/sup&gt; | n ≥ 0} to help us understand what the concept of Turing machines is.&lt;/p&gt;

&lt;p&gt;Before start trying to tackle this language and design a Turing machine for it, we should understand what string it contains. This language contains all ordered strings such that a's at the beginning of the string, b's at the middle and c's at the end where the number of a's, b's and  c's match.&lt;/p&gt;

&lt;p&gt;Our Turing machine should match one a with one b with one c and keep looping until the entire string is matched to accept the string. Here's a visualized of this procedure on the string aabbcc:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frzhtxobb9an4kmxsk0dx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frzhtxobb9an4kmxsk0dx.gif" alt="Animation for how the TM should be processed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the first iteration, the leftmost "a" will be converted to "A" symbol (can be any other symbol). Then the scanner will skip all small a's and convert the leftmost "b" to "B" symbol. Then the scanner will skip all small b's and convert the leftmost "c" to "C" symbol. After that, the scanner will go left skipping all "C" symbols, b's, "B" symbols and a's until it reaches an "A" symbol and it will go right to start the matching process again. At this point, the scanner will be on the left most "a" (note it's a small "a") and it'll proceeds as the first iteration with a minor difference is that the Turing machine will skip any "B" and "C" symbols. After the scanner finishes matching and goes back to the rightmost "A", it will move one cell to the right which is a cell that contains "B". When the scanner faces "B" symbol after moving on cell right, it's a sign that the string is matched. Then it will move to the right skipping all "B"  and "C" symbols to verify that the b's and c's are all matched. The Turing machine will halt in a final state if after skipping all  "B" and "C" symbols, the scanner reached a blank.&lt;/p&gt;

&lt;p&gt;Here's the Turing machine design that accepts the Language L:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frzfmzh0pfl69k0910jv3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frzfmzh0pfl69k0910jv3.png" alt="TM design for the language L"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the end of this post, I'd recommend a few resources if you'd like to acquire more knowledge about Turing machines: &lt;br&gt;
1- &lt;a href="https://plato.stanford.edu/entries/turing-machine/" rel="noopener noreferrer"&gt;Turing Machines published by Stanford&lt;/a&gt;&lt;br&gt;
2- &lt;a href="https://youtu.be/dNRDvLACg5Q" rel="noopener noreferrer"&gt;Turing Machines Explained - Computerphile&lt;/a&gt;&lt;br&gt;
3- &lt;a href="https://books.google.com.sa/books/about/An_Introduction_to_Formal_Languages_and.html?id=hsxDiWvVdBcC&amp;amp;printsec=frontcover&amp;amp;source=kp_read_button&amp;amp;redir_esc=y#v=onepage&amp;amp;q&amp;amp;f=false" rel="noopener noreferrer"&gt;An Introduction to Formal Languages and Automata by Peter Linz&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>An Overview of Pushdown automata (PDA)</title>
      <dc:creator>Hani</dc:creator>
      <pubDate>Tue, 24 Dec 2019 11:31:50 +0000</pubDate>
      <link>https://forem.com/sebhani/introduction-to-pushdown-automata-pda-4n1l</link>
      <guid>https://forem.com/sebhani/introduction-to-pushdown-automata-pda-4n1l</guid>
      <description>&lt;p&gt;Let's take a look at the context-free language L={a&lt;sup&gt;n&lt;/sup&gt;b&lt;sup&gt;n&lt;/sup&gt; | n ≥ 1}. How can we design a finite automaton (i.e. DFA/NFA) that accepts this language? To design a finite automaton that accepts this language, we should store the number of a's in some sort of memory in order to compare it to the number of b's. However, this's impossible due to the non-existence of memory in finite automata.&lt;/p&gt;

&lt;p&gt;In this post, i'm going to walk you through the concept of PDAs and tackle how we can design machines that accept context-free languages.&lt;/p&gt;

&lt;h2&gt;Table of Contents&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Informal Definition&lt;/li&gt;
&lt;li&gt;Formal Definition&lt;/li&gt;
&lt;li&gt;
Stack Manipulation &lt;/li&gt;
&lt;li&gt;Non-deterministic VS. Deterministic PDAs&lt;/li&gt;
&lt;li&gt;Example&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id="title1"&gt;Informal Definition&lt;/h2&gt;

&lt;p&gt;Let's think of PDAs as finite automata with a memory. This memory is simply a stack that can be manipulated as a part of the finite automata moves. The stack has initially a single symbol at the bottom of it which is denoted by Z (can be different in various textbooks).&lt;/p&gt;

&lt;p&gt;Transitions in PDAs are of the form δ(q, a, A) contains (p, x) which means when you're in state q, if you see 'a' on input and A on top of stack:&lt;br&gt;
• Go to state p&lt;br&gt;
• Replace A on the stack with the string x (leftmost symbol of x is on top of the stack). Here's the above transition depicted:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3czmztr3x42grzhwun0n.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3czmztr3x42grzhwun0n.gif" alt="Transition simulation"&gt;&lt;/a&gt;&lt;br&gt;
Note that the colored parts in the stack indicate strings.&lt;/p&gt;

&lt;p&gt;An input string is accepted if after the entire string is read, the PDA reaches a final state. It's important to mention that the stack contents are irrelevant to the acceptance of the string.&lt;/p&gt;

&lt;h2 id="title2"&gt;Formal Definition&lt;/h2&gt;

&lt;p&gt;Non-deterministic Push-Down Automaton is a septuple M = (Q, Σ, Γ, δ, q0, Z, F) where Q is a finite set of states&lt;br&gt;
Σ is a finite input alphabet&lt;br&gt;
Γ is a finite stack alphabet&lt;br&gt;
q0 is the start state&lt;br&gt;
Z ∈ Γ is the stack start symbol&lt;br&gt;
F ⊆ Q is the set of final states&lt;br&gt;
δ : Q × Σ U {λ} × Γ → finite set of subsets of Q × Γ&lt;sup&gt;*&lt;/sup&gt; is a transition function.&lt;/p&gt;

&lt;p&gt;Language accepted by a PDA M = (Q, Σ, Γ, δ, q0, Z, F) is the set L(M) = {w ∈ Σ&lt;sup&gt;*&lt;/sup&gt; | (q0, w, Z) ⊢&lt;sup&gt;∗&lt;/sup&gt; (p, λ, u), p ∈ F, u ∈ Γ&lt;sup&gt;∗&lt;/sup&gt;}&lt;/p&gt;

&lt;p&gt;The PDA accepts all strings w for which you can reach the final&lt;br&gt;
state at the end of the string &lt;strong&gt;(the stack contents are irrelevant)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id="title3"&gt;Stack Manipulation&lt;/h2&gt;

&lt;p&gt;Let's say we have the following transition: δ(q, a, A) contains (p, x). The following table demonstrates how we'd manipulate the stack by replacing the x symbol by others. Note that A and B are single symbols and not strings and the red portion indicates that the stack contents can be anything &lt;strong&gt;(i.e. we only care about the top of the stack)!&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;x&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;λ&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fm50a84fwhqkubo7gpje8.png" alt="Stack with an "&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6l8lolfykpy4jkzpj854.png" alt="Same stack as the initial one with the symbol "&gt;&lt;/td&gt;
&lt;td&gt;Pop the top of the stack&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fm50a84fwhqkubo7gpje8.png" alt="Stack with an "&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkmc61wcj6igy322o7du7.png" alt="Same stack as the initial one with the symbol "&gt;&lt;/td&gt;
&lt;td&gt;Replace "A" with "B"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BA&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fm50a84fwhqkubo7gpje8.png" alt="Stack with an "&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxvo2c9nsfif1li9s09yl.png" alt="Same stack as the initial one with the symbol "&gt;&lt;/td&gt;
&lt;td&gt;Push "B" on the top of "A"&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;How do we write the transition on the PDA graph? The answer is: &lt;br&gt;
symbol you read, top of the stack, stack manipulation.&lt;br&gt;
Example: a, A, B which means if you read an "a" and the top of the stack is "A", go to the state that the transition arrow points to and replace the "A" with "B" in the stack.&lt;/p&gt;

&lt;h2 id="title4"&gt;Non-deterministic VS. Deterministic PDAs&lt;/h2&gt;

&lt;p&gt;The only difference between NPDAs and DPDAs is that the latter has two restrictions: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;δ(q, a, b) contains at most one element, so the following is prohibited in DPDAs&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F222wwznkcf2kh46cn5dz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F222wwznkcf2kh46cn5dz.png" alt="Prohibited transition 1"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If δ(q, λ, b) is not empty, then δ(q, a, b) = Ø for all a ∈ Σ, so the following is prohibited in DPDAs&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8qtzequ5tggizi2srsfx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8qtzequ5tggizi2srsfx.png" alt="Prohibited transition 2"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Unlike finite automata , &lt;strong&gt;not every NPDA has an equivalent DPDA.&lt;/strong&gt; Therefore, the class of deterministic and non-deterministic languages are not equivalent.&lt;/p&gt;

&lt;h2 id="title5"&gt;Example&lt;/h2&gt;

&lt;p&gt;Let's take the language L={wcw&lt;sup&gt;R&lt;/sup&gt; | w ∈ (a+b)&lt;sup&gt;∗&lt;/sup&gt;} as an example. The general approach to design an NPDA for this language is to push all symbols you encounter until you encounter the symbol c which is a sign that the reverse string must occur. Then your NPDA should compare what is on the stack to what is being read until the stack is empty which is a sign that the w&lt;sup&gt;R&lt;/sup&gt; string has occurred.&lt;/p&gt;

&lt;p&gt;Here's the NPDA design with a simulation for the input string abcba:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwx7g7ory30h60hopmzsj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwx7g7ory30h60hopmzsj.gif" alt="NPDA design for the given language"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the end of this post, I'd like to suggest a few resources that I think would be helpful if you want to acquire more knowledge about Pushdown automata:&lt;br&gt;
1- &lt;a href="https://www.cs.wcupa.edu/rkline/fcs/pdas.html" rel="noopener noreferrer"&gt;Pushdown Automata: PDA-DPDA by Robert M. Kline&lt;/a&gt;&lt;br&gt;
2- &lt;a href="https://brilliant.org/wiki/pushdown-automata/" rel="noopener noreferrer"&gt;Pushdown Automata by Brilliant&lt;/a&gt;&lt;br&gt;
3- &lt;a href="https://books.google.com.sa/books/about/An_Introduction_to_Formal_Languages_and.html?id=hsxDiWvVdBcC&amp;amp;printsec=frontcover&amp;amp;source=kp_read_button&amp;amp;redir_esc=y#v=onepage&amp;amp;q&amp;amp;f=false" rel="noopener noreferrer"&gt;An Introduction to Formal Languages and Automata by Peter Linz&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Handling OS-level Authentication Dialogues in Internet Explorer using Selenium + AutoIt</title>
      <dc:creator>Hani</dc:creator>
      <pubDate>Sun, 08 Sep 2019 18:09:24 +0000</pubDate>
      <link>https://forem.com/sebhani/handling-os-level-authentication-dialogues-in-internet-explorer-using-selenium-autoit-4mhk</link>
      <guid>https://forem.com/sebhani/handling-os-level-authentication-dialogues-in-internet-explorer-using-selenium-autoit-4mhk</guid>
      <description>&lt;p&gt;For a few weeks, I've been working on a Selenium project and I'd to figure out a way to handle authentication dialogues in Internet Explorer (IE). The dilemma is that IE dialogues are non-browser dialogues, i.e., Windows-based dialogues. Therefore, they can't be handled using Selenium since Selenium doesn't recognize OS-level dialogues. I'll walk you through my solution which consists of two parts.&lt;/p&gt;

&lt;p&gt;I used Selenium C# WebDriver. For other programming languages users, the concepts in this article are still applicable. You may need to import or use AutoIt package in a different way but nothing is really hard.&lt;/p&gt;

&lt;p&gt;1- IE Settings:&lt;/p&gt;

&lt;p&gt;I want IE to prompt the users to enter their credentials each time they open the browser because I'd like to run my tests against different users.&lt;/p&gt;

&lt;p&gt;In your IE browser, click on Settings &amp;gt; Internet options &amp;gt; Security tab &amp;gt; check Enable Protected Mode &amp;gt; click on Custom level… &amp;gt; check Prompt for user name and password. Repeat the last three steps on all four zones (Internet, Local internet, Trusted sites, Restricted sites).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7vv9gdufet1ko4rqqhw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7vv9gdufet1ko4rqqhw9.png" alt="IE settings demo #1" width="749" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frh7sxzo49ol1y3z9d2b4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frh7sxzo49ol1y3z9d2b4.png" alt="IE settings demo #2" width="414" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After applying the previous steps, IE should prompt the user to enter their credentials every time they open it.&lt;/p&gt;

&lt;p&gt;2- C# code&lt;/p&gt;

&lt;p&gt;To tackle the problem of Windows-based dialogues, I utilized a scripting language called AutoIt. By integrating AutoIt with Selenium, I was able to handle Windows- based dialogues smoothly. Let's dive into the C# code.&lt;/p&gt;

&lt;p&gt;First step is to add AutoIt NuGet Package in Visual Studio. &lt;a href="https://docs.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio" rel="noopener noreferrer"&gt;Refer to Microsoft Documentation&lt;/a&gt;. After referencing AutoIt NuGet Package (&lt;code&gt;using AutoIt;&lt;/code&gt;), you will get a class named AutoItX with static methods ready to be used.&lt;/p&gt;

&lt;p&gt;I created a method that takes the user credentials and handles the windows-based dialogues.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;SetAuthenticationCredentials&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;UserName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Pws&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;AutoItX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WinWaitActive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Windows Security"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;AutoItX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;UserName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;AutoItX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{TAB}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;AutoItX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Pws&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;AutoItX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{ENTER}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A number of people ran into an exception after this step, so here's one way to use the previous method properly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Parallel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Navigate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;GoToUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"https://YourWebsite.com"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;SetAuthenticationCredentials&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"usertest2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"password2"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this way, you'll navigate to your website and invoke the SetAuthenticationCredentials method simultaneously.&lt;/p&gt;

&lt;p&gt;Congratulations!!! right now you should be able to handle Windows-based dialogues easily. If you have any question, please don't hesitate asking me.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>selenium</category>
      <category>csharp</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
