devchaminda

Please help my scripts giving an error

5 posts in this topic

#1 ·  Posted (edited)

Hi,

 

When I running scenario_page.au3 page its gives following error message popup.

Error opening workbook 'C:Dev_ChamindaQAAutomation_TestingTest_Data

@error = 2, @extended = 0

 

System running read_excel_file.au3 page without an issue, when I run that page only.

 

My code as below.

;/////////////////;///////////////////////read_excel_file.au3;/////////////////;/////////////////////////
#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>

$sResult = Call("readexcel", "C:\Dev_Chaminda\QA\Automation_Testing\Test_Data\", "MyTest.xls", "Sheet1", "B", "2")
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", $sResult)

Func readexcel($filepath, $filename, $sheetval, $colnam, $rowval)
    ; Create application object and open an example workbook
    Local $oAppl = _Excel_Open(False)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($oAppl, $filepath & $filename, False, False, '', '')
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error opening workbook '" & $filepath & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oAppl)
        Exit
    EndIf

    ; *****************************************************************************
    ; Read data from a single cell on the active sheet of the specified workbook
    ; *****************************************************************************
    Local $cellval = $colnam & $rowval
    Local $sResult = _Excel_RangeRead($oWorkbook, $sheetval, $cellval)
    ;_Excel_BookClose ( $oWorkbook,True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Return $sResult
EndFunc   ;==>readexcel
;/////////////////;///////////////////write_excel_file.au3;/////////////////;//////////////////////
#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>

$sResult = Call("writexcel", "C:\Dev_Chaminda\QA\Automation_Testing\Test_Data\", "Test.xls", "Sheet1", "DEV", "A", "1")

Func writexcel($filepath, $filename, $sheetval, $val, $colnam, $rowval)
    ; Create application object and open an example workbook
    Local $oAppl = _Excel_Open(False)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($oAppl, $filepath & $filename, False, False, '', '')
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error opening workbook '" & $filepath & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oAppl)
        Exit
    EndIf

    ; *****************************************************************************
    ; Read data from a single cell on the active sheet of the specified workbook
    ; *****************************************************************************
    Local $range = $colnam & $rowval
    Local $sResult = _Excel_RangeWrite($oWorkbook, $sheetval, $val, $range)
    ;_Excel_BookClose ( $oWorkbook,True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
EndFunc   ;==>writexcel
;/////////////////////////////my_login.au3;/////////////////;/////////////////////////////

#include <IE.au3>
#include <MsgBoxConstants.au3>

Func openbrowser($serval, $hostval)
    Local $url = "http://" & $serval & "/" & $hostval & "/frmLogin.aspx"
    Global $oIE = _IECreate($url, 0, 1, 1, 1)
    _IELoadWait($oIE)
EndFunc   ;==>openbrowser

Func IElogin($serval, $hostval, $myusr, $mypass)
    Local $url = "http://" & $serval & "/" & $hostval & "/frmLogin.aspx"
    _IENavigate($oIE, $url)
    _IELoadWait($oIE)
    Local $usr = _IEGetObjByName($oIE, "ctl00$cphMainContent$txtUserName")
    Local $psr = _IEGetObjByName($oIE, "ctl00$cphMainContent$txtPassword")
    _IEFormElementSetValue($usr, $myusr)
    _IEFormElementSetValue($psr, $mypass)
    Send("{ENTER}")
    _IELoadWait($oIE)
    Return $myusr & ", Successfully login."
EndFunc   ;==>IElogin

Func IElogout($serval, $hostval)
    Local $url = "http://" & $serval & "/" & $hostval & "/frmLogin.aspx"
    _IENavigate($oIE, $url)
    _IELoadWait($oIE)
    _IEQuit($oIE)
    Return "Successfully logout."
EndFunc   ;==>IElogout

Func closebrowser()
    _IEQuit($oIE)
    Return "Close browser."
EndFunc   ;==>closebrowser
;/////////////////;/////////////////////scenario_page.au3;/////////////////////////////

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <write_excel_file.au3>
#include <read_excel_file.au3>
#include <my_login.au3>
#include <Array.au3>
#include <Excel.au3>

Local $serval = Call("readexcel", "C:\Dev_Chaminda\QA\Automation_Testing\Test_Data\", "MyTest.xls", "Sheet1", "B", "2")
Local $hostval = Call("readexcel", "C:\Dev_Chaminda\QA\Automation_Testing\Test_Data\", "MyTest.xls", "Sheet1", "C", "2")
Local $usr = Call("readexcel", "C:\Dev_Chaminda\QA\Automation_Testing\Test_Data\", "MyTest.xls", "Sheet1", "D", "2")
Local $psr = Call("readexcel", "C:\Dev_Chaminda\QA\Automation_Testing\Test_Data\", "MyTest.xls", "Sheet1", "E", "2")

Call("openbrowser", $serval, $hostval)
Local $res = Call("IElogin", $serval, $hostval, $usr, $psr)
Call("IElogout", $serval, $hostval)
Call("closebrowser")
Call("writexcel", "C:\Dev_Chaminda\QA\Automation_Testing\Test_Data\", "MyTest.xls", "Sheet1", $res, "F", "2")
;/////////////////;/////////////////;/////////////////;/////////////////;///////////////////////////
Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites



devchaminda,

Welcome to the AutoIt forums. :)

When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

The error message is telling you the problem, @error = 2 on _Excel_BookOpen means it cannot find the file. Make sure the file is where you think it is in your directory structure. If you want more than this, you're going to have to provide full code, including your custom includes, or a pared down reproducer that removes these functions.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

No need to use "Call".

; $sResult = Call("readexcel", "C:\Dev_Chaminda\QA\Automation_Testing\Test_Data\", "MyTest.xls", "Sheet1", "B", "2")
$sResult = readexcel("C:\Dev_Chaminda\QA\Automation_Testing\Test_Data\", "MyTest.xls", "Sheet1", "B", "2")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi All,

Its working after i create a new scenario page.

Thanks Melba23 and thank others as well.

I am planing to automate web application using AutoIT and its kind of pilot project(find a alternative for Selenium). I get to know this tool in 2011, but now i see may improvement. Since this is an free tool this has very good help file and its really impressive, that lets me to use this tool now and really great-full to thanks every one who gave their contribution to take this tool up to this level.

..................

Thanks

Dev chaminda

Share this post


Link to post
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