Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using demoskype.PageObjects.LoginPage.LoginControllerClasses;


namespace demoskype
{
    /// <summary>
    /// Summary description for CodedUITest1
    /// </summary>
    [CodedUITest]
    public class CodedUITest1
    {
        public CodedUITest1()
        {
        }

        [TestMethod]
        public void CodedUITestMethod1()
        {
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            Console.WriteLine("welcome");
            
            ApplicationUnderTest.Launch(@"C:\Program Files (x86)\Skype\Phone\Skype.exe");
            Console.WriteLine("welcome");
            LoginController objLogin = new LoginController();
            HtmlEdit userNameEdit = objLogin.UISkypeWindow.UIItemClient.UISkypeDocument.UISkypeNameEdit;
            Mouse.Click(userNameEdit);
            Keyboard.SendKeys(userNameEdit, "automation.aahlaad");
            HtmlEdit passwordEdit = objLogin.UISkypeWindow.UIItemClient.UISkypeDocument.UIPasswordEdit;
            Mouse.Click(passwordEdit);
            Keyboard.SendKeys(passwordEdit, "aahlaad123");

            HtmlHyperlink signInLink = objLogin.UISkypeWindow.UIItemClient.UISkypeDocument.UISigninHyperlink;
            Mouse.Click(signInLink);
        }

        #region Additional test attributes

        // You can use the following additional attributes as you write your tests:

        ////Use TestInitialize to run code before running each test 
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{        
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //}

        ////Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{        
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //}

        #endregion

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        private TestContext testContextInstance;
    }
}
Posted
Updated 30-Aug-15 22:26pm
v2
Comments
nivedita mirjikar 31-Aug-15 2:39am    
How to add a reference to the object for launching skype
nivedita mirjikar 31-Aug-15 2:40am    
C:\Users\Aahlaad-w\Desktop\Skype>ipy CombineLibrary.py

C:\Users\Aahlaad-w\Desktop\Skype>cd C:\Users\Aahlaad-w\Desktop\Skype

C:\Users\Aahlaad-w\Desktop\Skype>robot.bat text.txt

C:\Users\Aahlaad-w\Desktop\Skype>set pythonExec="C:\IronPython2.7\ipy.exe"

C:\Users\Aahlaad-w\Desktop\Skype>set runner="C:\IronPython2.7\Lib\site-packages\
robot\run.py"

C:\Users\Aahlaad-w\Desktop\Skype>"C:\IronPython2.7\ipy.exe" "C:\IronPython2.7\Li
b\site-packages\robot\run.py" text.txt
==============================================================================
Text
==============================================================================
Valid_Element_Combination .#########
######################
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Valid_Element_Combination | FAIL |
ValueError: The following is not a valid technology name: Web. To search for a c
ontrol, you must specify a valid technology name.
Parameter name: TechnologyName
------------------------------------------------------------------------------
Text | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\Users\Aahlaad-w\Desktop\Skype\output.xml
Log: C:\Users\Aahlaad-w\Desktop\Skype\log.html
Report: C:\Users\Aahlaad-w\Desktop\Skype\report.html

C:\Users\Aahlaad-w\Desktop\Skype>pause
Press any key to continue . . .

C:\Users\Aahlaad-w\Desktop\Skype>robot.bat text.txt

C:\Users\Aahlaad-w\Desktop\Skype>set pythonExec="C:\IronPython2.7\ipy.exe"

C:\Users\Aahlaad-w\Desktop\Skype>set runner="C:\IronPython2.7\Lib\site-packages\
robot\run.py"

C:\Users\Aahlaad-w\Desktop\Skype>"C:\IronPython2.7\ipy.exe" "C:\IronPython2.7\Li
b\site-packages\robot\run.py" text.txt
==============================================================================
Text
==============================================================================
Valid_Element_Combination | FAIL |
"The application cannot be started. This could be due to one of the following re
asons:
1) Another instance of the application is already running and only one instance
can be running at a time.
2) The application started another process and has now stopped. You may need to
launch the process directly.
3) You do not have sufficient privileges for this application." File: C:\Program
Files (x86)\Skype\Phone\Skype.exe.
------------------------------------------------------------------------------
Text | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\Users\Aahlaad-w\Desktop\Skype\output.xml
Log: C:\Users\Aahlaad-w\Desktop\Skype\log.html
Report: C:\Users\Aahlaad-w\Desktop\Skype\report.html

C:\Users\Aahlaad-w\Desktop\Skype>pause
Press any key to continue . . .

C:\Users\Aahlaad-w\Desktop\Skype>robot.bat text.txt

C:\Users\Aahlaad-w\Desktop\Skype>set pythonExec="C:\IronPython2.7\ipy.exe"

C:\Users\Aahlaad-w\Desktop\Skype>set runner="C:\IronPython2.7\Lib\site-packages\
robot\run.py"

C:\Users\Aahlaad-w\Desktop\Skype>"C:\IronPython2.7\ipy.exe" "C:\IronPython2.7\Li
b\site-packages\robot\run.py" text.txt
==============================================================================
Text
==============================================================================
Valid_Element_Combination | FAIL |
The following error occurred when this process was started: Object reference not
set to an instance of an object. File: C:\Program Files (x86)\Skype\Phone\Skype
.exe.
------------------------------------------------------------------------------
Text |
nivedita mirjikar 31-Aug-15 2:41am    
the above commands i have used to run the C# script and i am getting the error
Richard MacCutchan 31-Aug-15 3:13am    
Where? Please do the following:
- remove all these redundant comments
- edit your question and add <pre> tags around your code (remove the code not relevant to the problem)
- show which line the error occurs on, and which variable is in error
Herman<T>.Instance 31-Aug-15 4:26am    
Nice codedump. What do you expect now?

1 solution

This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself.

Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which means that there is no instance of a class in the variable.
It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen. If you reach into the pocket and find there isn't a pen there, you can't sign your name on a piece of paper - and you will get very funny looks if you try! The empty pocket is giving you a null value (no pen here!) so you can't do anything that you would normally do once you retrieved your pen. Why is it empty? That's the question - it may be that you forgot to pick up your pen when you left the house this morning, or possibly you left the pen in the pocket of yesterdays shirt when you took it off last night.

We can't tell, because we weren't there, and even more importantly, we can't even see your shirt, much less what is in the pocket!

Back to computers, and you have done the same thing, somehow - and we can't see your code, much less run it and find out what contains null when it shouldn't.
But you can - and Visual Studio will help you here. Run your program in the debugger and when it fails, VS will show you the line it found the problem on. You can then start looking at the various parts of it to see what value is null and start looking back through your code to find out why. So put a breakpoint at the beginning of the method containing the error line, and run your program from the start again. This time, VS will stop before the error, and let you examine what is going on by stepping through the code looking at your values.

But we can't do that - we don't have your code, we don't know how to use it if we did have it, we don't have your data. So try it - and see how much information you can find out!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900