首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >程序是否定义了多个入口点?main()的CS0017问题?

程序是否定义了多个入口点?main()的CS0017问题?
EN

Stack Overflow用户
提问于 2019-07-31 23:59:22
回答 1查看 10.4K关注 0票数 4

当我尝试在visual studio中运行下面的代码时,我得到了以下错误:“程序定义了多个入口点。使用/main编译以指定包含入口点的类型。”

我尝试过寻找其他入口点,但对c#并不是很有经验,在这方面遇到了麻烦。据我所知,一切都应该是正确的。

代码语言:javascript
复制
namespace Demos
{
using System;
using System.Drawing;
using Applitools;
using Applitools.Selenium;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

public class HelloWorld2
{
    static string appName = "Hello World 2 App C#";

    // change the value of testName so that it has a unique value on your Eyes system
    static string testName = "Hello World 2 v1";

    // if you have a dedicated Eyes server, set the value of the variable serverURLstr to your URL
    static string serverURLstr = "https://eyesapi.applitools.com";

    //set the value of runAsBatch to true so that the tests run as a single batch
    static Boolean runAsBatch = true;

    // set the value of changeTest to true to introduce changes that Eyes will detect as mismatches
    static Boolean changeTest = true;

    static string weburl = "https://applitools.com/helloworld2";

    public static void Main(string[] args)
    {
        var eyes = new Eyes();
        eyes.ServerUrl = serverURLstr;
        setup(eyes);

        var viewportSizeLandscape = new Size(/*width*/1024, /*height*/ 768);
        var viewportSizePortrait = new Size(/*width*/500, /*height*/ 900);
        IWebDriver innerDriver = new ChromeDriver();

        if (!changeTest) 
        {
            Test01(innerDriver, eyes, viewportSizeLandscape);
            Test01Changed(innerDriver, eyes, viewportSizePortrait);
        } 
        else 
        {
            Test01Changed(innerDriver, eyes, viewportSizeLandscape);
            Test01Changed(innerDriver, eyes, viewportSizePortrait);
        }
        innerDriver.Quit();
    }


    private static void Test01(IWebDriver innerDriver, Eyes eyes, Size viewportSize) 
    {
        // Start the test and set the browser's viewport size
        IWebDriver driver = eyes.Open(innerDriver, appName, testName, viewportSize);
        try 
        {
            driver.Url = weburl;
            eyes.CheckWindow("Before enter name");                 // Visual checkpoint 1

            driver.FindElement(By.Id("name")).SendKeys("My Name"); //enter the name
            eyes.CheckWindow("After enter name");                  // Visual checkpoint 2

            driver.FindElement(By.TagName("button")).Click();      // Click the  button
            eyes.CheckWindow("After Click");                       // Visual checkpoint 3

            Applitools.TestResults result = eyes.Close(false);     //false means don't thow exception for failed tests
            HandleResult(result);
        } 
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        } 
        finally 
        {
            eyes.AbortIfNotClosed();
        }
    }
              

    private static void HandleResult(TestResults result) 
    {
        string resultStr;
        string url = result.Url;
        if (result == null) 
        {
            resultStr = "Test aborted";
            url = "undefined";
        } 
        else 
        {
            url = result.Url;
            int totalSteps = result.Steps;
            if (result.IsNew) 
            {
                resultStr = "New Baseline Created: " + totalSteps + " steps";
            } 
            else if (result.IsPassed) 
            {
                resultStr = "All steps passed:     " + totalSteps + " steps";
            } 
            else 
            {
                resultStr = "Test Failed     :     " + totalSteps + " steps";
                resultStr += " matches=" +  result.Matches;      /*  matched the baseline */
                resultStr += " missing=" + result.Missing;       /* missing in the test*/
                resultStr += " mismatches=" + result.Mismatches; /* did not match the baseline */
            }
        }
        resultStr += "\n" + "results at " + url;
        Console.WriteLine(resultStr);
    }

     private static void Test01Changed(IWebDriver innerDriver, Eyes eyes, Size viewportSize) 
    {
        // Start the test and set the browser's viewport size
        IWebDriver driver = eyes.Open(innerDriver, appName, testName, viewportSize);
        try 
        {
            string webUrlToUse = weburl;
            if (changeTest) 
            {
                webUrlToUse += "?diff2";
            } 
            driver.Url = webUrlToUse;
            if (!changeTest) 
            {  
                eyes.CheckWindow("Before enter name");             // Visual checkpoint 1
            }
            driver.FindElement(By.Id("name")).SendKeys("My Name"); //enter the name
            eyes.CheckWindow("After enter name");                  // Visual checkpoint 2

            driver.FindElement(By.TagName("button")).Click();      // Click the  button
            eyes.CheckWindow("After click");                       // Visual checkpoint 3

            if (changeTest) 
            {  
                eyes.CheckWindow("After click again");             // Visual checkpoint 3
            }
            TestResults result = eyes.Close(false); //false means don't thow exception for failed tests
            HandleResult(result);
        } 
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        } 
        finally 
        {
            eyes.AbortIfNotClosed();
        }
    }

    private static void setup(Eyes eyes) 
    {
        eyes.ApiKey = Environment.GetEnvironmentVariable("APPLITOOLS_API_KEY");
        if (runAsBatch)
        {
            var batchInfo = new Applitools.BatchInfo("Hello World 2 Batch");
            eyes.Batch = batchInfo;
        }
        //eliminate artifacts caused by a blinking cursor - on by default in latest SDK
        eyes.IgnoreCaret = true;
    }
}
}
EN

回答 1

Stack Overflow用户

发布于 2020-01-15 19:27:10

尝试将此代码添加到.csproj项目文件中:

代码语言:javascript
复制
<PropertyGroup>
    <GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57294824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档