Jump to content

FireFox Tab Verification


Recommended Posts

#include <Excel.au3>
Local $oExcel = _ExcelBookNew() ;Create new book, make it visible
Opt("MouseCoordMode",0)
#region ---Au3Recorder generated code Start (v3.3.7.0)  ---

#region --- Internal functions Au3Recorder Start ---
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
EndFunc

Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc


#endregion --- Internal functions Au3Recorder End ---


Run('"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"')
Sleep(1000)
_WinWaitActivate("Google - Mozilla Firefox","")
$pass=_WinWaitActivate("Google - Mozilla Firefox","")
if $pass=_WinWaitActivate("Google - Mozilla Firefox","") Then

    _ExcelWriteCell($oExcel, "Pass", 1, 1) ;Write to the Cell
Elseif $pass=_WinWaitActivate("Google - Mozilla Firefox","") Then

    _ExcelWriteCell($oExcel, "Fail", 1, 1) ;Write to the Cell
EndIf
Sleep(1000)
MouseClick("left",236,95,1)
Sleep(1000)
Send("{BACKSPACE}www.jettysoft.com{DEL}{ENTER}")
Sleep(1000)
_WinWaitActivate("JettySoft - Mozilla Firefox","")
Sleep(1000)
MouseClick("left",1256,15,1)
Sleep(1000)
_WinWaitActivate("Confirm close","")
Sleep(1000)
MouseClick("left",178,115,1)
#endregion --- Au3Recorder generated code End ---

Hi, i am trying to pass or fail to excel, when i am openingĀ  google i am trying to send the pass to excel and if it opening the different url i am trying to send fail.

But i couldn't able to put if condition and verifying conditions. Please help i am facing this problem from months

Link to comment
Share on other sites

I cannot understand your post, but this makes less sense.

if $pass=_WinWaitActivate("Google - Mozilla Firefox","") Then

    _ExcelWriteCell($oExcel, "Pass", 1, 1) ;Write to the Cell
Elseif $pass=_WinWaitActivate("Google - Mozilla Firefox","") Then

    _ExcelWriteCell($oExcel, "Fail", 1, 1) ;Write to the Cell
EndIf

Both conditions appear to me, to be the same.

AutoIt Absolute BeginnersĀ  Ā  Require a serialĀ  Ā  Pause ScriptĀ  Ā  Video Tutorials by MorthawtĀ  Ā ipifyĀ 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

if $pass=_WinWaitActivate("Google - Mozilla Firefox","") Then    
 _ExcelWriteCell($oExcel, "Pass", 1, 1) ;Write to the Cell
 Elseif $pass=_WinWaitActivate("Yahoo Canada - Mozilla Firefox","") Then     
_ExcelWriteCell($oExcel, "Fail", 1, 1) ;Write to the Cell EndIf

I tried in this way but else if condition is not working. i don't Know, what is UDF. how to use it? Could any one explain to me

Link to comment
Share on other sites

you are setting $pass equal to your function "_WinWaitActivate" but that function returns no values.

Try changing your function like this so you are returning a value

WinWaitActive returns the following:

Success: Returns handle to the requested window. Failure: Returns 0 if timeout occurred.
Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    Return WinWaitActive($title,$text,$timeout)
EndFunc
Edited by Shrapnel
Link to comment
Share on other sites

sorry for that,

i am trying to test , when i open firefox it should open default webpage (www.google.com) if it opens default webpage then my test case is passed so now i want to report in to excel that it is passed.Ā  or if it opens the different url otherĀ  than (www.google.com) then my test case is failed so i want to report it as failed.

Edited by veerendra
Link to comment
Share on other sites

$PID = Run('"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"')
ProcessWait($PID)
Sleep(1000); might want to wait longer.

If _IsGoogle($PID) Then
    ;do stuff
    MsgBox(0,0,"Yay")
    Exit
EndIf

;do other stuff
MsgBox(0,0,"Booo")

Func _IsGoogle($PID)
    Opt("WinTitleMatchMode",2)
    Local $hWnd = _GetHwndFromPID($PID)
    Local $WinTitle = WinGetTitle($hWnd)
    If StringInStr($WinTitle, "Yahoo -") Then
        Return 1
    EndIf
    Return 0
EndFunc

Func _GetHwndFromPID($PID)
    ;http://www.autoitscript.com/forum/topic/86680-pid-window-handle-hwnd-conversion/#entry621521
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc ;==>_GetHwndFromPID

AutoIt Absolute BeginnersĀ  Ā  Require a serialĀ  Ā  Pause ScriptĀ  Ā  Video Tutorials by MorthawtĀ  Ā ipifyĀ 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Here is the version that I was working on (just posting because it was slightly different):

#include <Excel.au3>

Local $oFireFox = Run('"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"')
ProcessWait($oFireFox)

Sleep(5000)

Local $hwndFireFox = _GetHwndFromPID($oFireFox)

If Not WinActive($hwndFireFox) Then WinActivate($hwndFireFox)

Local $FireFoxTitle = WinGetTitle($hwndFireFox)

Local $oExcel = _ExcelBookNew() ;Create new book, make it visible

If $FireFoxTitle = "Google - Mozilla Firefox" Then
    _ExcelWriteCell($oExcel, "Pass", 1, 1) ;Write to the Cell
Else
    _ExcelWriteCell($oExcel, "Fail", 1, 1) ;Write to the Cell
EndIf

Exit

Func _GetHwndFromPID($PID)
    ;http://www.autoitscript.com/forum/topic/86680-pid-window-handle-hwnd-conversion/#entry621521
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc ;==>_GetHwndFromPID
Link to comment
Share on other sites

i am testing the windows application, it has the feature of parental control. i will block a website(www.google.com) to open, know i want to test the website is blocked or not.

so here i will pass different url(yahoo) so it should open yahoo. but www.google.com should be blocked.

Link to comment
Share on other sites

#include <Excel.au3>
Local $oExcel = _ExcelBookNew()
Opt("WinTitleMatchMode", 2)
Run('"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"')
WinWaitActive("Firefox")
Sleep(5000)
;MsgBox(1, "Done", WinGetTitle("[active]"))
Local $title = WinGetTitle("[active]")
If (StringInStr($title, "Google - Mozilla Firefox", 0)) = 0 Then
    _ExcelWriteCell($oExcel, "Pass", 1, 1) ;Write to the Cell
   MsgBox(1, "Done", "Test Failed")
Else
    _ExcelWriteCell($oExcel, "Fail", 1, 1) ;Write to the Cell
   MsgBox(1, "Done", "Test Passed")
EndIf

i tried this

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...